Continue learning
Practice related DSA questions in the same topic.
Return the index of the first lowercase letter appearing exactly once, or -1.
Return the index of the first lowercase letter appearing exactly once, or -1.
def solve(values, target): counts = [0] * (26) i = 0 while (i < len(values)): letter = values[i] counts[letter] = (counts[letter] + 1) i = (i + 1) i = 0 while (i < len(values)): if (counts[values[i]] == 1): return i i = (i + 1) return -1Increase this letter's frequency.
Increase this letter's frequency.
After tallying votes, revisit the original queue to find the earliest solo vote.
Count every character before deciding which occurrence is unique.
O(n + 26) time · O(26) auxiliary space
Worked example · {"values":[3,1,3,2],"target":0} ⇒ 1
Edge case 1 · {"values":[0,0],"target":0} ⇒ -1
Edge case 2 · {"values":[],"target":0} ⇒ -1
Iterating the alphabet returns the smallest unique character, which can occur later.
What information must a streaming solution retain?