At Spotify, a common text-processing task is to quickly identify the first character in a string that appears exactly once. Given a string s, return the index of the first non-repeating character. If no such character exists, return -1.
s-1 if none existsExample 1
s = "leetcode"0'l' appears once and is the first such character.Example 2
s = "loveleetcode"2'v' is the first character that appears exactly once.Example 3
s = "aabb"-11 <= len(s) <= 10^5s contains only lowercase English lettersA correct solution should avoid comparing every character against every other character. Aim for a linear-time approach using an auxiliary data structure for counting.