First Letter Seen Twice
You are given a string text. Read it from left to right and return the first character you meet for the second time. If no character appears twice, return an empty string "".
The text may hold any characters: letters from any alphabet, digits, spaces and punctuation. Upper and lower case are different characters, so "A" and "a" are not a repeat.
Examples
text = "abccba" → "c"
text = "programming" → "r"
text = "world" → ""
text = "a-b-c" → "-"In "programming", the letters p, r, o, g are new; the fifth character, r, has been seen before. The two ms and two gs repeat later, so they do not count.
Constraints
- Between 0 and 20,000 characters.
- Aim for O(n): look at each character once.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.