• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 14, 2022 |3.5K Views
Java Program to Find the First Non-Repeating Character from a Stream of Characters
  Share  1 Like
Description
Discussion

In this video, we will write a Java program to find the first non-repeating character from a stream of characters. 

For this, we use a Doubly Linked List to find the first non-repeating character from a string. The DLL contains all non-repeating characters in order that is head of the DLL contains the first non-repeating character, and the second node contains the second non-repeating character, and so on. 

Here we will also maintain two arrays: 
1) One array is to maintain characters that are already visited two or more times. 
2) Second array is an array of pointers to linked list nodes. 

Algorithm: 
Step 1: Create an empty DLL. 
Step 2: Create two arrays inDLL[] and repeated[]. 
Step 3: In DLL is an array of pointers to DLL nodes, and repeated[] is a boolean array, if x is repeated two or more times, repeated[x] is true. otherwise false. 
Step 4: In DLL[x] contains a pointer to a DLL node if character x is present in DLL, otherwise NULL.

Example: 
Input: "Geekg" 
Output: k 

Find the first non-repeating character from a stream of characters
https://www.geeksforgeeks.org/find-first-non-repeating-character-stream-characters/

Read More