Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

First Unique Character Index

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is First Unique Character Index. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

At Spotify, you are given a lowercase string s and need to find the index of the first character that appears exactly once. If no such character exists, return -1.

Formal Specification

  • Input: A string s containing only lowercase English letters.
  • Output: An integer representing the index of the first non-repeating character, or -1 if every character repeats.

Constraints

  • 1 <= len(s) <= 10^5
  • s contains only lowercase English letters

Function Signature

def first_unique_char(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output