Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

String and Python Coding Practice

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

Your question is String and Python Coding Practice. 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

A Syapse patient-event label may contain repeated characters. Given a string s, return the first character encountered during a left-to-right scan that has already appeared. If no character repeats, return None.

The result is based on the first repeated occurrence, not the character with the earliest original position. For example, in "abccba", return "c" because the second c is encountered before the second a or b.

Formal Specification

Implement first_repeating_character(s), where s is a string and the return value is either a one-character string or None. Treat uppercase and lowercase letters as different characters, and count spaces and punctuation as valid characters.

Constraints

  • 0 <= len(s) <= 100,000
  • s may contain Unicode characters, whitespace, and punctuation
  • Character comparisons are case-sensitive

Function Signature

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