First non-repeating character in a stream
Submissions: 24972   Accuracy:


  Difficulty: Medium   Marks: 4
Associated Course(s):   Interview Preparation

Given an input stream 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 no non repeating element is found print -1.

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N denoting the size of the stream. Then in the next line are x characters which are inserted to the stream.

For each test case in a new line print the first non repeating elements separated by spaces present in the stream at every instinct when a character is added to the stream, if no such element is present print -1.

1 <= T <= 200
1 <= N <= 500


a a b c
a a c

a -1 b b
a -1 c

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.