First Non-Repeating Character
Given a string s of lowercase letters, return the index of the first character that appears exactly once in the whole string. If every character repeats, return -1.
Example 1
Input: s = "rotator" Output: 3 Explanation: 'r', 'o' and 't' repeat; 'a' at index 3 is the first that does not.
Example 2
Input: s = "aabb" Output: -1
Constraints
- 1 <= s.length <= 10^5
- s consists of lowercase English letters.
Hint 1
Count how many times each character appears in one pass.
Hint 2
In a second pass, return the first index whose count is 1.
Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer
Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.