8

Java Program to Find the First Non-Repeating Character from a Stream of Characte...

 2 years ago
source link: https://www.geeksforgeeks.org/videos/java-program-to-find-the-first-non-repeating-character-from-a-stream-of-characters/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java Program to Find the First Non-Repeating Character from a Stream of Characters

Java Program to Find the First Non-Repeating Character from a Stream of Characters
Hello everyone. Welcome to Geeks for
  • 370 Views
  • 14/08/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK