Problem 194133 · medium · Level 01 Prerequisites & Setup

The First Key Pressed Twice

strings · iteration · sets · membership

A keyboard logger stores every key press, in order, as the string s. Reading the log from the start, find the first press of a key that had already been pressed earlier, and return that character. Capital and small letters are different keys, and spaces and punctuation are keys like any other. If no key is ever pressed twice, 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…