Intermediate Level
Implement the firstNonRepeatingCharacter method that returns the first character in the text that appears only once.
The input contains a string text. Your task is to return the first character that appears only once in the string.
If every character is repeated, return #. For example, in aabbcde, the first non-repeating character is c.
First count how many times each character appears in the string.
Then scan the string again from left to right. The first character with frequency 1 is the answer. If no such character exists, return #.
Pseudocode:
function firstNonRepeatingCharacter(text):
frequency = empty map
for each character in text:
frequency[character]++
for each character in text:
if frequency[character] == 1:
return character
return '#'