• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
March 20, 2024 |180 Views
SDE Sheet - First non-repeating character in a stream
  Share   Like
Description
Discussion

This video is part of Stack and Queue section under GFG SDE Sheet.

In this problem, an input stream A of n characters consisting only of lower case alphabets. While reading characters from the stream, you have to tell which character has appeared only once in the stream upto that point. If there are many characters that have appeared only once, you have to tell which one of them was the first one to appear. If there is no such character then append '#' to the answer.

NOTE:
1. You need to find the answer for every i (0 <= i < n)
2. In order to find the solution for every i you need to consider the string from starting position till ith position.

Example :

Input: A = "aabc"
Output: "a#bb"
Explanation: For every ith character we will
consider the string from index 0 till index i 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" - there are two non repeating characters 'b' and 'c', first non-repeating character is 'b' because 'b' comes before 'c' in the stream.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/find-first-non-repeating-character-stream-characters/
Problem: https://www.geeksforgeeks.org/problems/first-non-repeating-character-in-a-stream1216/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More