You are given a string s
consisting of lowercase English letters. Determine the first character that repeats in the string and return it. If no character repeats, return an empty string.
Q: Can we assume the input string only contains lowercase English letters? A: Yes.
Q: Is it possible for the input string to be empty? A: Yes, and if the string is empty, the function should return an empty string.
Q: Should we consider non-consecutive repeats? A: Yes, any character that appears more than once in the string.
Q: What should be returned if there are no repeated characters in the string? A: An empty string.
def first_letter_to_appear_twice(s: str) -> str:
seen = set()
for char in s:
if char in seen:
return char
seen.add(char)
return ""
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?