Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

First Unique Character in a String

XPChallenge Points: 10
levelLevel: Easy

You are given a string s.
Your task is to locate the first character that appears exactly once in the entire string.
Return the index of that character.
If no such character exists, return -1.


Example 1:

Input: s = "swiss"

Output: 1

Explanation:

'w' is the first non-repeating character.

Example 2:

Input: s = "aabcbd"

Output: 3

Explanation:

Characters: 'a' repeats 'b' repeats 'c' repeats 'd' at index 4 is the first character appearing once.

Example 3:

Input: s = "zzxxcc"

Output: -1

Explanation:

Every character occurs more than once.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result