Skip to main content
LeetCode 387, Easy. Topics: Hash Table, String, Queue, Counting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

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

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026