I recently interviewed with a company in the bay area (CA,USA). One of the questions was to simply find if a string has repeated characters(I have simplified a lengthy question).
eg: input : "qwerrty" output : True
I used python to code this.
I gave a solution that uses a set to track the elements encountered during the iteration.
However the interviewer wanted me to use an array[255] that tracks the characters encountered.
Although I was quite comfortable using either of them, my opinion was to use a set simply because we are wasting 255 character space when we use an array. This is because (as we all know) initially we create an arr[255] = 0 all elements being zero and then increment the ASCII equivalent index value by 1.
A set on the other hand would spend memory only on the elements visited.
Since he (kind of) argued to use an array over a set I am curious to know if he was technically correct. Is array preferred over a set/map in this case? If so, why?