Problem 194133 · medium · Phase 01 Prerequisites & Setup

First Repeated Character

strings · iteration · sets · membership

Given a string s, return the first character that appears for the second time while reading left to right. Comparison is case-sensitive and every character counts (spaces and punctuation too). If no character repeats, return "".

Examples

Input:  s = "abcba"
Output: "b"

Input:  s = "abcdef"
Output: ""

Constraints

  • 0 <= len(s) <= 5000
  • s may contain any printable characters

Goals

  • Remember characters already seen
  • Stop at the first character that was seen before
  • Return a sentinel when nothing repeats
Starting Python…