Practice

First Unique Character

Module 6 · Hash Tables

Problem

Given a string s, return the index of the first character that appears exactly once, or −1 if none exists.

Examples

Example 1

Input"leetcode"Output0

Explanation. l

Example 2

Input"loveleetcode"Output2

Explanation. v

Example 3

Input"aabb"Output-1

Constraints

1 ≤ n ≤ 10⁵ · lowercase English letters.

Attempt it first

The patterns-lesson quiz literally contained this problem's shape. The one design decision worth pausing on: why must there be two passes, and over what?