First Non-Repeating Character

arrays · function

Description

Given a string, return the index of the first character that does NOT
repeat anywhere else in the string. "Repeating" means occurring more
than once anywhere in the string -- nothing to do with adjacency.
If no such character exists, return -1.

Example:
    s = "loveleetcode"
    -> 2 ('v' is the first character whose total count in s is 1.
          'l', 'o', 'e' all appear more than once.)

Traps:
- "First character that's unique SO FAR" is wrong. You need overall
  counts across the whole string, not a running first-seen check.
  e.g. "abcabd" -> 2 ('c'), not 0 ('a' repeats later).
- Comparison is case-sensitive: 'a' and 'A' are distinct.
- Empty string returns -1.

Constraints

- 0 <= len(s) <= 10^5
- s may contain any unicode characters (don't assume ASCII-only)
- Case-sensitive
solution.py
output
Run the cases to see results here.