First repeat
Inputs
text is 0 to 16 lowercase letters (a to z).
Your tasks
- Create an empty string
seenthat will hold the letters you have already visited. - Use a loop over
text. If the current character is already inseen, return it right away. Otherwise add it toseen. - Complete
firstRepeatso it returns the first letter that shows up a second time, or an empty string. Return it, do not print it.
Example
With text = "abcbad", firstRepeat returns "b".
Rules
- If no letter repeats, return an empty string.
Test data
TEST DATA 1: text is "abcbad"
TEST DATA 2: text is "abc"
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.