Timer: 10 min, like in an interview. Hints and autocomplete are off while it runs
First non-repeating character
MediumMap and Set10 min
Write a function firstUniqueChar(text) that returns the first character of the string text that appears in it exactly once. If there is no such character, return null.
- "First" means the leftmost in
text: in'swiss'the answer is'w'. - Letter case matters:
'a'and'A'are different characters. - Every character counts, also spaces, digits and punctuation.
- An emoji such as 🐞 is one character. Return it whole, not half of it.
- An empty string gives
null.
Examples
firstUniqueChar('swiss')Returns 'w'
firstUniqueChar('aabb')Returns null
firstUniqueChar('aA')Returns 'a'
Loading the editor...
- Input
firstUniqueChar('swiss')Expected'w' - Input
firstUniqueChar('aabb')Expectednull - Input
firstUniqueChar('aA')Expected'a'
Hidden tests run on Submit