InferenceAI

Enter at least two characters to search.

Start free

First Unique Letter

easyArrays & Hashing15 min10 XP

Return the index of the first character of s that occurs exactly once, or -1 if every character repeats.

Examples

EXAMPLE WALKTHROUGHfirst letter

A guided view of the published example, not a trace of your code.

INPUT["leetcode"]
TASKfirst_unique_letter()
EXPECTED OUTPUT0

Start with the input values shown in this example.

Example 1 of 3

Input: s = "leetcode"

Output: 0

Explanation: first letter

Input: s = "loveleetcode"

Output: 2

Explanation: later letter

Input: s = "aabb"

Output: -1

Explanation: none

Hint 1

Count first, then scan again.

Topics

DSAArrays & HashingPython