PythonMediumHashing20 min
Find the first non-repeated character
The input contains lowercase English letters only. Preserve the original order when choosing the result. Interviewers use this problem to assess count first, then scan the original order.
Input
One line of lowercase letters, possibly empty.
Output
Print the result on one line; print an empty line for an empty string.
Constraints
0 <= length <= 100000.
Example
Input
swiss
Output
w
Example 2 input
abacbd
Output
c
The first unique character need not be first overall.
Public test cases (2)
Input
swiss
Expected output
w
Input
aabb
Expected output
NONE
Hints (2)
- Identify the state needed to avoid repeated work.
- Count first, then scan the original order.
Target complexity: time O(n) · space O(1), since there are only 26 letters
