First Unique Character in a String

Easy

Company Tags

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

Example 1:

Input: s = "neetcodeislove"

Output: 0

Explanation: The character 'n' at index 0 is the first character that does not occur at any other index.

Example 2:

Input: s = "neetcodeneet"

Output: 4

Example 3:

Input: s = "baab"

Output: -1

Constraints:

  • 1 <= s.length <= 1,00,000
  • s consists of only lowercase English letters.


Company Tags

Please upgrade to NeetCode Pro to view company tags.

s =