First Non-Repeating Character
Given a string s made up of lowercase English letters, find the 0-based index of the first character that appears exactly once in the entire string. If every…
Given a string `s` made up of lowercase English letters, find the 0-based index of the first character that appears exactly once in the entire string. If every character appears more than once, return `-1`.
- `1 ≤ s.length ≤ 10⁵` - `s` consists of only lowercase English letters. - The interactive visualizer accepts at most 20 characters; longer valid judge inputs are execution-only.
Example 1: input s = "tornado"; output 0. Character frequencies: t→1, o→2, r→1, n→1, a→1, d→1. Scanning left to right, 't' at index 0 has a frequency of 1, so 0 is returned.
Example 2: input s = "aabb"; output -1. 'a' appears twice and 'b' appears twice. No character is unique, so return -1.
Example 3: input s = "river"; output 1. Frequencies: r→2, i→1, v→1, e→1. 'r' at index 0 repeats, but 'i' at index 1 appears exactly once — return 1.
Category: Strings. Topic: strings. Difficulty: Easy. Patterns: hashing.