first non repeating character in string
first non repeating character in string
Approach:
Create a count array of size 26(i am assuming only lower case characters are
present) and initialize it with zero.
Create a queue of char datatype.
Store each character in queue and increase its frequency in the hash array.
For every character of stream, we check front of the queue.
If the frequency of character at the front of queue is one, then that will be the
first non-repeating character.
Else if frequency is more than 1, then we pop that element.
If queue became empty that means there are no non-repeating characters so we will
print -1.
import java.util.LinkedList;
import java.util.Queue;