PIXELBANKv9.1.0
Menu

First Unique Character in a String

Given a string s, find the first non-repeating character and return its index. Return -1 if no such character exists.

Example:

Input:
leetcode
Output:
0
Reasoning:
  • First, we count the frequency of each character in the string s = leetcode.
  • Then, we iterate over the string to find the first character with a frequency of 11.
  • We find that the character l appears only once and it is the first character in the string, so its index is 00.
  • The final output is the index of the first non-repeating character, which is 00.

Constraints:

  • 1 <= len(s) <= 10^5
  • s consists of lowercase English letters
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
First Unique Character in a String - Easy | PixelBank