First non-repeating character in a Stream | LinkedList | GFG | Love Babbar DSA Sheet | Amazon🔥🔥

  Рет қаралды 23,447

Yogesh & Shailesh (CodeLibrary)

Yogesh & Shailesh (CodeLibrary)

Күн бұрын

#Linkedlist #competitiveprogramming #coding #dsa
Hey, Guys in this video I have explained with code how we can solve the problem 'First non-repeating character in a stream '.
Join our Telegram Channel for more Information
🔰 Telegram Channel Link = t.me/CodeLibrary1
🔰 Get 10% OFF on all GeeksforGeeks Courses
Coupon Code = CODELIBRARY
🔰 Array Playlist = • Love Babbar DSA 450 Qu...
🔰 String Playlist = • Love Babbar DSA 450 Qu...
🔰 Searching and Sorting Playlist = • Love Babbar DSA 450 Qu...
🔰 Binary Tree Playlist = • Love Babbar DSA 450 Qu...
🔰 Linked List Playlist = • Love Babbar DSA 450 Qu...
🔰 Graph Playlist = • Love Babbar DSA 450 Qu...
🔰 Dynamic Programming Playlist = • Love Babbar DSA 450 Qu...
🔰 Informative Videos = • Informative Videos
🔰 Love Babbar DSA Sheet: drive.google.c...
Follow us on Instagram:
🔰 Shailesh Yogendra : / shaileshyogendra
🔰 Yogesh Yogendra : / i_am_yogesh_here
Follow us on LinkedIn:
🔰 Yogesh Yogendra : / yogesh-yogendra-26bbb518a
🔰 Shailesh Yogendra : / shailesh-yogendra-8b13...
Hope you like it. Comment if you have any doubt
LIKE | SHARE | SUBSCRIBE

Пікірлер: 34
@RajatSingh-vs6wu
@RajatSingh-vs6wu Жыл бұрын
If you are getting TLE on gfg there are two things you can do you optimize your code : 1) Currently the time complexity of the code in the video is O(n^2) since the size of the both the "vis" vector and "v" vector is n. This can be optimized down to a time complexity of O(26*n) by only adding unique characters in the "v" array instead of all the characters in the string. This will make sure that the size of "v" vector does not exceed 26. 2) Instead of iterating over the whole "v" array again and again from the 0th index to the last index, you can store the index of the previous "first unique" character found, say "X", and in the next iteration start the loop from "X" rather than the 0th index since if you won't be find your unique character in between 0th index and "X"th index anyways. Below is the updated code with these optimizations( I have used a map instead of "vis" vector) : string FirstNonRepeating(string A){ mapmp; vectorv; int n = A.size(); int cnt=0; string ans=""; for(int i =0;i
@MritunjayKumar-rd2es
@MritunjayKumar-rd2es Жыл бұрын
lekin main to linked list approach dekhne aya tha🥴🥴
@rishabsharma5307
@rishabsharma5307 3 жыл бұрын
Simple C++ Solution string FirstNonRepeating(string A){ // Code here string output; vector vect(26, 0); queue mq; for(auto x : A) { int idx = x - 'a'; if(vect[idx] == 1) vect[idx] = 2; else if(vect[idx] == 0) { vect[idx] = 1; mq.push(x); } while(!mq.empty() and vect[mq.front() - 'a'] == 2) mq.pop(); if(mq.empty()) output.push_back('#'); else output.push_back(mq.front()); } return output; }
@navendraagrawal
@navendraagrawal 2 жыл бұрын
thanks bro your solution is much better than this video
@maharishicoding440
@maharishicoding440 Жыл бұрын
Approach: 1. we have to find the 1st non repeating character not non repeating character only keep in mind. 2. So for that we have to initialize 3 thing 1. Array to keep the count of non repeating character, 2. Queue to Keep the record of 1st non repeating character,(you can use arraylist as well) 3. We also need a variable to store a result. 3. Now iterate increase the frequency of the array for repeating character and add the 1st non repeating char to the queue then add it to the String variable at each iteration. here is my Java code: class Solution { public String FirstNonRepeating(String A) { StringBuilder result = new StringBuilder(); // initialize a string to store the output int[] freq = new int[26]; // initialize an array to store the frequency of each character Queue queue = new LinkedList(); // initialize a queue to store the non-repeating characters // process each character in the input stream for (char c : A.toCharArray()) { freq[c - 'a']++; // increment the frequency of the current character // if the current character is non-repeating, add it to the queue if (freq[c - 'a'] == 1) { queue.add(c); } // remove all characters from the queue that are no longer non-repeating while (!queue.isEmpty() && freq[queue.peek() - 'a'] > 1) { queue.remove(); } // if there are no non-repeating characters in the queue, append "#" to the output string if (queue.isEmpty()) { result.append('#'); } else { // otherwise, append the first non-repeating character in the queue to the output string result.append(queue.peek()); } } return result.toString(); // return the output string } }
@faizannasimhyder9011
@faizannasimhyder9011 3 жыл бұрын
Thanks for the excel sheet more than the video bro. I will practice all the questions in sequence. In order to remain organized.
@hemantsurariya3239
@hemantsurariya3239 2 жыл бұрын
IDK , its showing TLE. I tried several time.
@DurgaShiva7574
@DurgaShiva7574 2 жыл бұрын
hi, thankyou for this amazing video... one quick question, i think the space complexity in your code is 52 ...and not 26..right?... because we have an visited array of 26 + another vector which might also range upto 26 characters at same time.. please let me know
@dhirendrasingh6071
@dhirendrasingh6071 2 жыл бұрын
It's considered constant space
@randomtalks1234
@randomtalks1234 6 ай бұрын
great explanation brother.......
@bhaveshsoni6684
@bhaveshsoni6684 3 жыл бұрын
if the same logic applies in python then where we store characters bcoz if we can store characters and their counter in the array, then its output is TLE....
@shahidagarwal2868
@shahidagarwal2868 3 жыл бұрын
Hello Yogesh. I have been seeing that you are doing some good to the community.. But instead of just running and explaining through your code which u already coded.. You can code in front of them so that they can understand it much more clearly.
@tusharsolanki8564
@tusharsolanki8564 3 жыл бұрын
yes definitely or ye pta chl jayega logic kese click hua
@CodeLibrary
@CodeLibrary 3 жыл бұрын
If I code in front of them then video will become too long that's why I explain in the already written codes😀
@Yash_Parashar
@Yash_Parashar 3 жыл бұрын
@@CodeLibrary please explain for last c in test case how your code give b??
@debdhritiroy6868
@debdhritiroy6868 3 жыл бұрын
12:28 very true, same algo java me TLE derha h, aur cpp me accept ofc, time limits java me zyada hone k bawajud
@hannanathar3627
@hannanathar3627 3 жыл бұрын
use stringBuilder for ans instead of string , it wont give TLE then
@rutujahande5850
@rutujahande5850 2 жыл бұрын
Here, output is coming as wrong - aabc ####
@yash_verma
@yash_verma Жыл бұрын
string ans will take O(n) space complexity
@malharsurangalikar6224
@malharsurangalikar6224 3 жыл бұрын
Same approach gives TLE for java on GFG
@nimratkaur6153
@nimratkaur6153 3 жыл бұрын
try using StringBuilder
@vishalsingh2408
@vishalsingh2408 3 жыл бұрын
Good job brother...
@payalsagar1808
@payalsagar1808 3 жыл бұрын
Thanks a lot😁
@shivamdalania
@shivamdalania 3 жыл бұрын
Can someone please explain me how this is related to linked list?
@AnkitSingh-wq2rk
@AnkitSingh-wq2rk 3 жыл бұрын
Doubly Linked list ka question hai yeh Ek queue maintain karenge Doubly LL type jisme possible candidates for First non repeating char rakhenge in case agar element repeat hota hai toh woh ab possible candidate nhi hoga first non rep ke liye hence hame use queue se nikalna hoga so for O(1) deletion we are using LL
@Piyush-yd1ez
@Piyush-yd1ez 3 жыл бұрын
Ye question queue section me bhi hai.
@mdsaifhussainiqbal2236
@mdsaifhussainiqbal2236 2 жыл бұрын
queue approach code string FirstNonRepeating(string str) { int n = str.size(); queue q; unordered_map umap; string ans = ""; for(int i=0;i
@MrCoder-xj9yi
@MrCoder-xj9yi 3 жыл бұрын
good job, keep it up!
@yuvrajsharma2134
@yuvrajsharma2134 Жыл бұрын
noice
@deepanshukumar7290
@deepanshukumar7290 3 жыл бұрын
bhai quick sort
@prajwalingole1584
@prajwalingole1584 3 жыл бұрын
opppp
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 38 МЛН
Inside Out 2: ENVY & DISGUST STOLE JOY's DRINKS!!
00:32
AnythingAlexia
Рет қаралды 18 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 40 МЛН
First non repeating character in a stream | Leetcode #387
11:23
Animation vs. Math
14:03
Alan Becker
Рет қаралды 71 МЛН
Differences Between Minecraft Java VS Bedrock
11:41
Skip the Tutorial
Рет қаралды 10 МЛН
TCS Campus Interview I Campus Placements I Gauri Shrimali I Arvind Singh Pemawat
18:09
You Can't Call Yourself a Driver If You Don't Know These 9 Secrets
8:11
Fractional Knapsack Problem | Greedy | GFG | Love Babbar DSA Sheet | Amazon🔥🔥
12:16
Yogesh & Shailesh (CodeLibrary)
Рет қаралды 18 М.
First Unique Character in a String | LeetCode problem 387
9:57
Technosage
Рет қаралды 10 М.
FASTEST Way to Learn Coding and ACTUALLY Get a Job
8:50
Sahil & Sarra
Рет қаралды 7 МЛН
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 38 МЛН