Given a string s consisting of lowercase English letters, return the first letter to appear twice.
A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.
s will contain at least one letter that appears twice.
Function Signature
def repeated_character(s: str) -> str:
Rules
-
Return the letter as a one-character string.
-
Only the position of each letter's second occurrence matters. A letter that appears three or more times is ranked by its second occurrence.
Constraints
-
2 <= s.length <= 100
-
s
consists of lowercase English letters.
-
s
has at least one repeated letter.
Examples
Input: s = "abccbaacz"
Output: "c"
Scanning left to right, a, b and c are new at indices 0 to 2, and c is seen again at index 3. The second b (index 4) and the second a (index 5) come later, so the answer is c.
Input: s = "abcdd"
Output: "d"
Only d repeats, and its second occurrence is at index 4.