Skip to content
← Back to the archive

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,000
  • s contains only lowercase English letters

Function signature

def first_unique_index(s: str) -> int:

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.