Given an input stream of A of n characters consisting only of lower case alphabets. The task is to find the first non repeating character, each time a character is inserted to the stream. If there is no such character then append '#' to the answer.
Input: A = "aabc" Output: "a#bb" Explanation: For every character first non repeating character is as follow- "a" - first non-repeating character is 'a' "aa" - no non-repeating character so '#' "aab" - first non-repeating character is 'b' "aabc" - first non-repeating character is 'b'
Input: A = "zz" Output: "z#" Explanation: For every character first non repeating character is as follow- "z" - first non-repeating character is 'z' "zz" - no non-repeating character so '#'
You don't need to read or print anything. Your task is to complete the function FirstNonRepeating() which takes A as input parameter and returns a string after processing the input stream.
Expected Time Complexity: O(26 * n)
Expected Space Complexity: O(26)
1 <= n <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes