12 August 2026
First Unique Index
Medium
Strings
Find the first character that refuses to repeat. A small scan with a useful counting twist.
Given a lowercase string s, return the zero-based index of its first character that appears exactly once in the entire string. Return -1 if every character repeats.
Constraints
1 <= len(s) <= 100,000s contains only lowercase English letters
Function signature
def first_unique_index(s: str) -> int: