JavaMediumStrings20 min
Find the first non-repeated character
Print the first character occurring exactly once, or NONE if no such character exists. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe boundary handling and collection selection.
Input
One line of lowercase English letters, possibly empty.
Output
Print the first character occurring exactly once, or NONE if no such character exists.
Constraints
0 <= length <= 100000.
Example
Input
swiss
Output
w
Example 2 input
leetcode
Output
l
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
swiss
Expected output
w
Input
aabb
Expected output
NONE
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Count characters first, then scan in original order to find the earliest unique character.
Target complexity: time O(n) · space O(1)
