First Letter to Appear Twice
Updated
Problem statement
You are given a string s of lowercase English letters. Return the first letter to appear twice.
Reading from left to right, this is the letter whose second appearance comes earliest. s always contains at least one letter that appears twice.
Function
repeatedCharacter(s: String) → charExamples
Example 1
s = "abcbda"return = "b"Reading left to right, b shows up again at index 3, before a shows up again at index 5. So the answer is b.
Example 2
s = "abba"return = "b"a appears first, but its second appearance is at index 3. b appears again at index 2, which is earlier, so the answer is b.
Example 3
s = "zz"return = "z"The second character repeats the first one.
Constraints
2 <= s.length <= 100sconsists of lowercase English letters.shas at least one repeated letter.
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Longest Non-Repeating SubstringPHONE SCREEN · Seen Jul 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Known Words Matching Phone DigitsLinkedIn · PHONE SCREENLinkedIn interview questions
- First Non-Repeated CharacterDell Technologies · PHONE SCREENDell Technologies interview questions
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- SimpleRDD Word CountDatologyAI · PHONE SCREEN