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
s— the input string (or list of characters, if reversing in place)
**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