text of lowercase English letters from left to right, noting each letter as you go. Return the letter you run into for the second time first.
In other words, every repeated letter has a position of its second occurrence; return the letter whose second occurrence comes earliest. At least one letter is guaranteed to repeat.text="rocketry" → 'r'
Only r repeats, at positions 0 and 6, so it is the answer.
text="banana" → 'a'
The second a is at index 3 and the second n at index 4, so a repeats first.
text="zz" → 'z'
text consists of lowercase English letterstext="rocketry"
'r'
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.