dsa · easy

First Unique Character in a String

GreyOrangeStringHash MapFoundation

Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

Arguments

**Example 1:** `` Input: s = "dojo" Output: 0 ``

Constraints

1 <= s.length <= 10^5 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
dojo

Expected:
0

Example 2

Input:
lovedojo

Expected:
2

Open in the Dojo editor