Easy · Frequency Map
Understand → Visualise → Practice.
Return the index of the first character occurring exactly once, or −1.
One pass counts every character; a second pass returns the first index whose character has count 1.
Build a frequency map of the whole string.
Walk the string again from the start.
Return that index, or −1 if every character repeats.
O(n) time and O(1) space for a fixed alphabet.
Checking each character against the rest of the string is O(n²).
Read the full guide first: Hash Maps and Hash Sets.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.