First Unique Character in a String — Rust Coding Problem
Difficulty: easy | Category: hash-map
Problem Description
Given a string `s`, find the **first** non-repeating character and return its index. If it does not exist, return `-1`. Hint: Count character frequencies with a hash map, then scan left to right for the first char with count 1.
Examples
Example 1
Input: s = "leetcode"
Output: 0
Explanation: "l" appears once and is at index 0.
Example 2
Input: s = "loveleetcode"
Output: 2
Explanation: "v" is the first unique character.
Example 3
Input: s = "aabb"
Output: -1