Ctrl K

First Letter Seen Again

Easy
You read a string 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.
Example 1
text="rocketry" → 'r'

Only r repeats, at positions 0 and 6, so it is the answer.

Example 2
text="banana" → 'a'

The second a is at index 3 and the second n at index 4, so a repeats first.

Example 3
text="zz" → 'z'
Constraints
  • 2 ≤ len(text) ≤ 100
  • text consists of lowercase English letters
  • At least one letter appears twice
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWords From Working Keys EasyPairs With the Same Letter Set EasyShuffle Into a Palindrome EasyNote From Clipped Letters EasyFirst One-Off Letter Easy
loading Python…
Input
text="rocketry"
Expected
'r'

Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.