#153EasyArrays & Hashing· Frequency Counting
First Unique Keystroke
Input format
`s`: a string of lowercase English letters.
Output format
An integer: the index of the first character that occurs exactly once in `s`, or -1 if there is none.
Examples
Input: s = "swiss"
Output: 1
s appears three times, w once, i once. The first letter that occurs exactly once is w at index 1.
Input: s = "aabb"
Output: -1
Both letters repeat, so no keystroke is unique.
Input: s = "abcabcd"
Output: 6
a, b and c each appear twice; d appears once and sits at index 6.
Constraints
- 1 <= s.length <= 10^5
- s consists of lowercase English letters (a-z).
Study first
- #hash-table
- #strings
- #counting