I would like to post some of the Brain Teaser (mostly algorithmic problems) Iām giving to interviewee lately, and of course some that were submitted to me in the past. But I canāt promise I will keep doing it regularly: just that I will try (blogging regularly is hard for me).
The solution will be at the end of the post, just in case you would like to try to solve it first. Of course my solution itās MY solution: it could be buggy or non-optimal. In those cases, PLEASE share your view and, better, your alternative solutions.
Problem description Determine the first non-repeated character in a word. For example, in abbcaf it should return c. Do this in [O(n)](http://en.wikipedia.org/wiki/Big_O_notation) time with O(1) space. Some observation O(n) means that the complexity of time of the algorithm must grow linearly with the input. So, if in this case the input is an array of characters, an acceptable solution can contain >1 non-nested FOR cycle. O(1) means that the complexity of space of the algorithm must be constant, regardlessly of the input.
Conditions For simplicity, will assume that: the input is always a lowercase string (enforcing this condition is easy and cheap)
the input is made made only of the letters of the english alphabet
Those conditions will then become the ābaseā of our solution.
Of course, you are free to assume more conditions: itās usually a good way to solve problems to start adding conditions that simplify the search of a solution, and then start a process of subtraction to arrive to have as less conditions as possible. It usually works for me.
...