Given a string of characters, return the index of the first non-repeating character.
Input: "abcdcaf"
Output: 1
The non-duplicate characters in the above string are b, d and f. Since b occurs first, the index of b, which is 1 is returned.
Input: "abcdefghabcdefgh"
Output: null
Since all the characters are repeating, null is returned.
String
1 <= str <= 26
Click to reveal
Try iterating over the array twice in a brute force way. Can you try comparing the values to come up with a solution?
Click to reveal
First HintTry using a Hash Map (objects in Javascript, map in C++, etc) to store the characters. It is not necessary to iterate over the array twice at the same time.