Sponsored Reserved space — layout preview until AdSense is connected
easy +12 pts

First non-repeating character

Two-pass ordered scan.

Implement `first_unique(s: str) -> int`. Return the index of the first non-repeating character, or -1 if none.

Constraints

0 ≤ len(s) ≤ 10^5; only lowercase letters.

Example

>>> first_unique("loveleetcode")
2
12 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Count all chars, then scan for first with count == 1.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected