Skip to content

Practice First Unique Character in a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#387
LeetCode Problem

First Unique Character in a String

Problem Statement

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

Source: First Unique Character in a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "leetcode"
Output
0

# Example 2

Input
s = "loveleetcode"
Output
2

# Example 3

Input
s = "aabb"
Output
-1

Constraints

1 <= s.length <= 10^5
s consists of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to First Unique Character in a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.