You get a string s. Some of its letters appear only once; others repeat. Reading from left to right, find the first letter that appears exactly once in the whole string and return its index. If every letter appears more than once, return -1.
Indices start at 0.
s repeats, so index 0 doesn't count. w at index 1 appears nowhere else. i is also unique, but it comes later.
r, a and c each appear twice. Only the e in the middle, at index 3, is alone.
Both n and o appear twice, so no letter qualifies.
Constraints
1 <= s.length <= 10⁵s is made of lowercase English letters only.Whether a letter is unique depends on the whole string, not just what you've read so far. Count first, decide second.
1