You are given a string s consisting of lowercase English letters. Your task is to find the first character that appears exactly once in the string and return its index position.
If no such unique character exists, return -1.
Example: In the string "leetcode", the character 'l' appears once at index 0, but 'e' appears multiple times. The first unique character is 't' at index 2.
This is a classic string processing problem that tests your ability to efficiently track character frequencies and find the optimal solution using hash tables.
Input & Output
Visualization
Time & Space Complexity
For each of n characters, we scan the entire string of length n
Only using constant extra space for counting
Constraints
- 1 โค s.length โค 105
- s consists of only lowercase English letters
- The string is guaranteed to be non-empty