Write firstRepeat(s) that reads the string s from left to right and returns the first character that you have already seen earlier in the string.
- In
"abba"the answer is"b". The secondb(index 2) comes before the seconda(index 3). - Characters are compared exactly:
"A"and"a"are different. Spaces and punctuation count as characters. - If no character appears twice, return
null. - Aim to read the string only once.
Input: s = "radar"
Output: "a"Reading left to right: r, a, d, then a again. The a repeats before the r does.
Input: s = "abba"
Output: "b"
Input: s = "abc"
Output: null