I came across this question. The question was to find the first repeating character in a string in log(N) time. I been cracking my head on this for a while and cannot come up with anything better than O(N). My idea was to use a hashset and do it in O(N). Can this be really done in log(N)? Since its log(N) obviously binary search was the first thing that came to my mind. But I am not sure how binary search would work? May be convert to ascii values ?
Aucun commentaire:
Enregistrer un commentaire