📣 Calling experienced devs and recent interviewees! Join the "Coding Problem Interview Series" to help code newbies tackle interview questions assessing problem-solving skills, algorithmic knowledge, and implementation of sorting, string manipulation, and data structure algorithms.
Share your expertise and insights! Pleas share multiple perspectives and tips for standout answers!
Today's question is:
Could you describe how you would find and print the first non-repeated character in a string?
Follow the CodeNewbie Org and #codenewbie for more discussions and online camaraderie!
Top comments (3)
Damn, it's more difficult then I thought! How about this solution in Java? I hope it's not dumb.
It's easier to check whether the character is repeated first. For this, we need to save the first char and loop through the rest of the string, looking for a similar one. Repeat for the 2nd, 3rd, and other chars. So it's a nested loop.
Then we need to add a boolean. If we find a repeated char, set the boolean to true, but if not, the condition in the outer loop will return from the method.
It's worth noticing that we need to :
i != index
to check if the experimental char is not the same char in the word;repeated
value to false every iteration because otherwise, it won't find any non-repeated chars in the word that starts with double letters e.g. "eerie";This can be done with two iterations.