• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 07, 2022 |5.0K Views
Queue based approach for first non-repeating character in a stream
Description
Discussion

Create a count array of size 26(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.


Queue based approach for first non-repeating character in a stream : https://www.geeksforgeeks.org/queue-based-approach-for-first-non-repeating-character-in-a-stream/

Read More