Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
First Unique Character Index
00:00
5 left

First Unique Character Index

EasyPython

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):
Interviewer

Your question is First Unique Character Index. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.