Easy · Strings

First Unique Character in a String

Given a string s of lowercase letters, return the index of the first character that appears exactly once in s, or −1 if every character repeats.

Examples

Example 1

{
  "s": "notebook"
}

Output: index 0

Example 2

{
  "s": "aabb"
}

Output: -1 (no unique char)

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Strings problems