30 Longest repeating subsequence

  Рет қаралды 204,416

Aditya Verma

Aditya Verma

Күн бұрын

Пікірлер: 353
@eren-qu9uu
@eren-qu9uu 4 жыл бұрын
This solution is also updated on GFG with 2nd part to print Longest repeating sub sequence u are actually helping GFG to updating its article.
@oaarian2014
@oaarian2014 2 жыл бұрын
untouchables ..dank bhai😂😂
@thorxn1382
@thorxn1382 3 ай бұрын
Is it funny
@nikhilraj5115
@nikhilraj5115 4 жыл бұрын
Bro ,do you have any plan to publish the series on "graph".
@Prince-fz6yo
@Prince-fz6yo 3 жыл бұрын
@OttoLyle @Mauricio Weston.. u both seems to be of same mother but diff fathers
@tushargupta6336
@tushargupta6336 3 жыл бұрын
no
@RuinsOfTheUnknown
@RuinsOfTheUnknown 3 жыл бұрын
@@Prince-fz6yo 😂😂😂😂
@arafatkhan5489
@arafatkhan5489 3 жыл бұрын
@@maharajak6578 bhai this weston dude's comment got deleted ig, what did he say tho?
@SHASHANKRUSTAGII
@SHASHANKRUSTAGII 3 жыл бұрын
@@arafatkhan5489 haha i also didnt get
@HarpreetSingh-mb2rk
@HarpreetSingh-mb2rk 2 жыл бұрын
literally the logic of this problem comes to my mind automatically after watching your DP playlist.
@ankitbhardwaj9566
@ankitbhardwaj9566 4 жыл бұрын
please make more videos on weighted graphs ,shortest paths ,prim ,krushkal ,,from codeforces
@jain007neeraj
@jain007neeraj 4 жыл бұрын
Whoever has confusion in the following inputs : AABABCD AXXXY. etc. Here is the explanation: Read this: Given a string, print the longest repeating subsequence such that the two subsequences don’t have same string character at same position The same Position is the twist here: A X X X Y ==> You can take X X [index0 and index1] and XX [index 1 and index2] X of index1 is used in both but its position in both substrings is different. In the first subsequence, it comes at 1st index whereas in the second subsequence comes at the 0th index.
@hemantmangwani1006
@hemantmangwani1006 4 жыл бұрын
Case :- AABCABB ANS :- 5 This question is little bit confusing read it twice if anyone is confused.
@DeepakKumar-yl3ok
@DeepakKumar-yl3ok 4 жыл бұрын
@@hemantmangwani1006 The answer should be 4 for the string "AABCABB" not 5
@koustav6884
@koustav6884 4 жыл бұрын
@@DeepakKumar-yl3ok yes
@bhaswatraj9433
@bhaswatraj9433 4 жыл бұрын
RAJ Kumar why is it not 3
@koustav6884
@koustav6884 4 жыл бұрын
@@bhaswatraj9433 No answer will be four you can cross check it by applying on algorithm
@mukeshranjanmallick8832
@mukeshranjanmallick8832 4 жыл бұрын
Whole Series is just awesome , Great explanation and thought process
@travellingsLenses
@travellingsLenses 3 жыл бұрын
Amazingly explained bro. Itne easy-going flow me samjhaya hai ki Binge watching chal rhi hai :D
@AJ-gg1jc
@AJ-gg1jc 4 жыл бұрын
no words to express your teaching...🤔🤩..... i was thinking about to solve it by this way that take both string and find lcs but then i defeated because they are same.... because of leaving idea in half way i was not able to solve that by own.... then you enlightened... you're great.....
@vivekmishra641
@vivekmishra641 Жыл бұрын
I relinquished the idea of taking the second string similar to first one due to the same reason.
@0anant0
@0anant0 4 жыл бұрын
29 of 50 (58%) done! Very nicely done!
@pr1493
@pr1493 3 жыл бұрын
It doesn't mean that you achieved something here, hold back and practice
@prateekchauhan5376
@prateekchauhan5376 2 жыл бұрын
@@pr1493 if u cant support, atleast don't be toxic
@pr1493
@pr1493 2 жыл бұрын
@@prateekchauhan5376 Just tried to push that guy to practice more without getting complacent, Don't know what ails you here lol 😂
@deepakpandey3485
@deepakpandey3485 2 жыл бұрын
@@pr1493 jada cool mat ban bhai... tune kya kiya you also know it.
@pr1493
@pr1493 2 жыл бұрын
@@deepakpandey3485 We can talk when you have a job
@vakhariyajay315
@vakhariyajay315 Жыл бұрын
Thank you very much. You are a genius.
@lalit2926
@lalit2926 3 жыл бұрын
Oh !! my bad, both strings are equal😂😂 @5:50 .. .. .. By the way your DP tutorial is best sir❤❤..
@umashankarpanigrahi
@umashankarpanigrahi Жыл бұрын
haha
@g1patil
@g1patil 3 жыл бұрын
5:46 . hahahha !! of course they all will match since they are same. jokes apart this had been one of the best learning for DP. Glad YT showed in search when I typed dynamic programming. Thanks a ton !!
@shivanidalmia2623
@shivanidalmia2623 4 жыл бұрын
Can you make a video on Longest Increasing subsequence.
@anandabhinav
@anandabhinav 4 жыл бұрын
Are simple h ye gfg p diya huaa h.. Arr1 -input arr Arr2 - arr1 ko sort karo. LCS(Arr1, Arr2)-> ans.. That's it bas itna sa hi h! 😎
@maximus6448
@maximus6448 4 жыл бұрын
@@anandabhinav If there will be repitition in array it will give wrong ans
@anandabhinav
@anandabhinav 4 жыл бұрын
@@maximus6448 bro binary search wala approach use karrlenge phirr.
@VIVEK1898
@VIVEK1898 3 жыл бұрын
@@yashbhanushali8456 remove duplicates from the sorted array.
@VIVEK1898
@VIVEK1898 3 жыл бұрын
@@anandabhinav remove duplicated from sorted array
@shritvaagarwal614
@shritvaagarwal614 3 жыл бұрын
Simply Genius!!...........Please bring graph series too
@saurabhmodi5128
@saurabhmodi5128 2 жыл бұрын
best explanation of the Longest repeating subsequence
@supriyakvs
@supriyakvs 28 күн бұрын
For string AAABA, the longest repeating subsequence is AAA. Because we can form AAA using 2 options here position 0,1,2 and position 1,2,4. Here, Characters are same but positions are different. That is what is mentioned in the question. I struggled with this because i thought it should be AA only. Hope this helps someone reading comments for clarification.
@saranghae3720
@saranghae3720 3 жыл бұрын
Those who don't get why i!=j, if s1 = "ABBC", s2 = "ABBC" then answer should be 1 which is "B" here when we create matrix : A B B C 0 1 2 3 4 0 0 0 0 0 0 A 1 0 0 0 0 0 B 2 0 0 0 1 0 B 3 0 0 1 0 0 C 4 0 0 1 1 1 so the answer will be 1 as s1 = "ABBC", s2 = "ABBC" in first iteration i = 1, when we at i index of B(s1), then we will not count ith index of B(s2), but we will count the ith+1 index, for i = 1 iteration and same is the case with jth iteration of B...
@paveshkanungo6338
@paveshkanungo6338 7 ай бұрын
One doubt here: why the answer is 1 which is "B", in the question (on gfg), an example is given like this: A = "xax" and B="xax" then first character "x" should have different indexes, the other can have same, answer of string s = "xxax" is 3 as "xax" and "xax" are the longest repeating subsequence, here "x" starting of both strings is having different indexes
@dhruvagarwal646
@dhruvagarwal646 3 жыл бұрын
We can also do for(int i=1; i
@kshitiz5621
@kshitiz5621 3 жыл бұрын
why ?
@dhruvagarwal646
@dhruvagarwal646 3 жыл бұрын
@@kshitiz5621 Because you can't use the same character in the repeating sequence.
@pranjaltiwari2344
@pranjaltiwari2344 4 жыл бұрын
After watching your playlist I think we should use - Bottom up approach when we have to print numbers, strings etc. - Top down approach when we have to count the numbers, characters etc. according to question. Well, thanks me later if you agree......
@hemantmangwani1006
@hemantmangwani1006 4 жыл бұрын
Ya you are right.
@ayansrivastava722
@ayansrivastava722 2 жыл бұрын
its actually interesting, that you should use tabulation where you have to perform operations on the created table itself, ie in such cases tabulation is necessary because it is just a mid part of a larger problem.
@Rohan-vl1ve
@Rohan-vl1ve Жыл бұрын
Thank you bro, you have great teaching and explaining skills
@pawankumarpandit1822
@pawankumarpandit1822 Жыл бұрын
thank you aditya bhaiya because of you i am able to solve the different kind of question
@sanyamsinghal7992
@sanyamsinghal7992 4 жыл бұрын
lovely explanation!! great work man ♥♥ please also make videos on graph topics like BFS, DFS and Shortest path.
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Will upload more video in the month of may !! Till then keep on sharing and help this channel grow + that keeps me motivated to make more videos !! ✌️❤️
@abhijitburman1260
@abhijitburman1260 4 жыл бұрын
@@TheAdityaVerma next video kab aayega bhaiya??
@krishnasai3367
@krishnasai3367 3 жыл бұрын
@@TheAdityaVerma its been more than a year, still no videos on graphs 😔😭
@Vishal-ds6ly
@Vishal-ds6ly Жыл бұрын
@@TheAdityaVerma its been than 2 year, still no videos on graphs.
@sidhantjha4566
@sidhantjha4566 Жыл бұрын
@@TheAdityaVerma We Want Graph Series.
@sumitkumar-oi5vq
@sumitkumar-oi5vq 4 жыл бұрын
This technique won't work for every test case. For string = 'ABEBACDD', The repeating subsequence is 'AD' only. As the order of subsequence matters, 'ABD' and 'BAD' can't be considered as equal. So the logic to compare only mismatch indexes will fail as it'll give output as 3 but the correct answer should be 2. One solution would be to remove all the repeating characters from the string s1 and store it in a separate variable s2, then if we take LCS of s1 and s2 that would give the answer. For string = 'ABEBACDD', s1='ABECD' (by removing repeating chars) s2='BAD' (removed chars in same order). LCS = 'AD' so length is 2. Let me know if this is incorrect. Don't want to mislead anyone :)
@vineetchaurasia6600
@vineetchaurasia6600 4 жыл бұрын
I tried this string with the approach explained in the video and got answer 2. Here's the top down matrix for this A B E B A C D D [0, 0, 0, 0, 0, 0, 0, 0, 0] A [0, 0, 0, 0, 0, 1, 1, 1, 1] B [0, 0, 0, 0, 1, 1, 1, 1, 1] E [0, 0, 0, 0, 1, 1, 1, 1, 1] B [0, 0, 1, 1, 1, 1, 1, 1, 1] A [0, 1, 1, 1, 1, 1, 1, 1, 1] C [0, 1, 1, 1, 1, 1, 1, 1, 1] D [0, 1, 1, 1, 1, 1, 1, 1, 2] D [0, 1, 1, 1, 1, 1, 1, 2, 2] sorry for the uneven spaces in top header row. I couldn't get the alignment right any other way
@vineetchaurasia6600
@vineetchaurasia6600 4 жыл бұрын
Another suggestion, you can change the inequality from (i != j) to (i < j). In effect it means that the ith character in 1st string can match a character at j in 2nd string only if its ahead of index (i). It gives a more understandable matrix A B E B A C D D [0, 0, 0, 0, 0, 0, 0, 0, 0] A [0, 0, 0, 0, 0, 1, 1, 1, 1] B [0, 0, 0, 0, 1, 1, 1, 1, 1] E [0, 0, 0, 0, 1, 1, 1, 1, 1] B [0, 0, 0, 0, 1, 1, 1, 1, 1] A [0, 0, 0, 0, 1, 1, 1, 1, 1] C [0, 0, 0, 0, 1, 1, 1, 1, 1] D [0, 0, 0, 0, 1, 1, 1, 1, 2] D [0, 0, 0, 0, 1, 1, 1, 1, 2]
@gunjanshinde396
@gunjanshinde396 2 жыл бұрын
Hello@@vineetchaurasia6600 , I found that this itself is correct, no need to change i < j. Reason being the other condition we are looking for which eliminates ABD and BAD in answers, is covered in LCD itself and we are getting '2' in second last place of last row because X[6] is compared to Y[7] which would never occurs as X == Y, X is string1 and Y is string 2. And, Thank You for the matrix, it really helped for me too.
@bhatanand
@bhatanand 2 жыл бұрын
solved it in an iterative way. DP is not needed for this. Here is the golang code: func sequencePattenMatching(str1,str2 string) bool { // Characters in str1 should match a subsequence in str2 i := 0 j := 0 str1Byte := []byte(str1) str2Byte := []byte(str2) for i < len(str1) && j < len(str2) { // Check if str1[i] is present in str2 for j < len(str2) && str1Byte[i] != str2Byte[j] { j++ } if j == len(str2) { return false } // Found // Increment i i++ } return true }
@chamangupta4624
@chamangupta4624 3 жыл бұрын
what does the cell value of dp matrix represent here ?? It represents the longest repeating subsequence that can be formed using the first x no. of elements of the given string , where x is the column no. of that cell
@vladimirputin2756
@vladimirputin2756 Жыл бұрын
public class longestRepeatingSubsequence { public static void main(String[] args) { String s1 = "axbyczapbqcr"; // "abc" is repeating here, so ans length is 3. String s2 = s1; // Create a copy of the input string s1 for comparison int n = s1.length(); // Length of string s1 int m = s2.length(); // Length of string s2 (copy of s1) // Create a 2D DP (Dynamic Programming) table with dimensions (n+1) x (m+1) int[][] dp = new int[n + 1][m + 1]; // Initialize the DP table with zeros for (int i = 0; i < n + 1; i++) { for (int j = 0; j < m + 1; j++) { if (i == 0 || j == 0) dp[i][j] = 0; // Base case: If either string is empty, LCS is 0. } } // Fill in the DP table using a top-down approach for (int i = 1; i < n + 1; i++) { for (int j = 1; j < m + 1; j++) { if (i != j && s1.charAt(i - 1) == s2.charAt(j - 1)) { // If the current characters match and the indices are not the same // (ensuring they are not the same character at the same position), // add 1 to the previous LCS length. dp[i][j] = 1 + dp[i - 1][j - 1]; } else { // If the current characters do not match or if the indices are the same, // take the maximum of the LCS when one character from either string is // excluded. dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); } } } // The value at dp[n][m] contains the length of the Longest Repeating // Subsequence (LRS). int result = dp[n][m]; // Print the length of the LRS. System.out.println("Length of Longest Repeating Subsequence: " + result); } }
@samarthbhawsar8739
@samarthbhawsar8739 3 жыл бұрын
Amazing Explanation🙌🙌 It's just like a magic happened in every video..👏👏🔥🔥
@hustler516
@hustler516 2 жыл бұрын
Bhaiya lol to ur teaching 🥰 ......who else wants to say the same lines to bhai with me
@siddheshjain8677
@siddheshjain8677 3 жыл бұрын
This was a very good question solved in an easiest manner ever!
@aniket6858
@aniket6858 Жыл бұрын
Bro we got AABBDD on taking all these conditions in mind.. shouldn't we do half of it to get final answer??
@nikhilranjan7126
@nikhilranjan7126 4 жыл бұрын
Awesome content I am waiting for more such videos... your explanation is good.
@samriddhashukla5345
@samriddhashukla5345 3 жыл бұрын
bhai chota sa question itna complicate kiya aapne maza aa gya
@aayush1204
@aayush1204 3 жыл бұрын
Hey, Aditya( I am again going to bother you lol) Are you thinking to upload videos on DP on grids and LIS anytime soon? Thanks in Advance 😀
@thinkingmad1685
@thinkingmad1685 3 жыл бұрын
Have you found any series like this for dp on grids, lis Or even understandable in yt pls suggest me 😔
@lovedeepsingh120
@lovedeepsingh120 2 жыл бұрын
@@thinkingmad1685 Watch Striver's DP playlist for these topics. He explained all of them very well..
@amarnathprasad1
@amarnathprasad1 3 жыл бұрын
Leaving a time capsule here. Interviews start Dec 1. If you see this after Dec 10, 2021, drop a comment! Update: I got placed at Unacademy in a Software Engineering role. Thank you Aditya! Your videos helped me a lot in getting my funda straight.
@MilindGupta
@MilindGupta 3 жыл бұрын
I will too drop right now in 5th sem... Preparing for interviews too
@kxnyshk
@kxnyshk 3 жыл бұрын
how did they go?
@amarnathprasad1
@amarnathprasad1 3 жыл бұрын
@@kxnyshk It went really well. I got placed at Unacademy in a Software Engineering role :). Thanks for your reply. I had totally forgotten about it. :D
@kxnyshk
@kxnyshk 3 жыл бұрын
@@amarnathprasad1 that's amazing. Congrats!
@amarnathprasad1
@amarnathprasad1 3 жыл бұрын
@@kxnyshk Thanks!
@ShivamSharma-bb1jx
@ShivamSharma-bb1jx 3 жыл бұрын
faad diya bro faad diya.....!!
@ManishYadav-eg4bl
@ManishYadav-eg4bl 3 жыл бұрын
Hn bhai.😅
@oqant0424
@oqant0424 3 жыл бұрын
Amazing Explanation🙌🙌
@abhi-5783
@abhi-5783 4 жыл бұрын
"Untouchables hai, nahi hai...". Lol
@AkashKumar-vc5yl
@AkashKumar-vc5yl 2 жыл бұрын
I think I have a better approach not sure if it always true: Find number of occurrences that are greater than 1. And divide each of them with the min repeating count and add them up. That is your longest repeating subsequence, Eg - ADBABDADA A - 4 B - 2 D - 3 Since B has min number of occurrence, divide each by 2. So, we get => 4/2 = 2, 2/2 = 1, 3/2 = 1 So longest repeating subsequence = 2 + 1 + 1 = 4. I tries it and it logically fits in as large string as size of 10. Not sure though.
@meenasharma9280
@meenasharma9280 2 жыл бұрын
but what about order try ABBAC
@23cash86
@23cash86 Жыл бұрын
before 10:00 for explanation.....12:00 for final answer ...bookmark for me XD
@SilentNight_Tour
@SilentNight_Tour 2 жыл бұрын
MZA AA GYA DP SEIES SIR
@Education_2753
@Education_2753 4 жыл бұрын
Sir plz complete this playlist of dynamic programming It's humble request sir plz Upload the video sir as soon as possible
@AMITKUMAR-ze9yo
@AMITKUMAR-ze9yo 3 жыл бұрын
thanks buddy :) , @5:50 leaving 'e' while finding LCS of same string was funny though :D
@rahulchudasama9363
@rahulchudasama9363 4 жыл бұрын
Hi Aditya, Big thank you, Can you please make a playlist of the graph ???
@samyakjain720
@samyakjain720 4 жыл бұрын
Bhai u made dynamic programming like sweet
@ngtv5608
@ngtv5608 3 жыл бұрын
Need a playlist on GRAPH !!
@rhythemjain1067
@rhythemjain1067 3 жыл бұрын
You should try Striver's Graph series. It really helped me in clearing my concepts.
@princenagar1686
@princenagar1686 9 ай бұрын
6: 36 it's wrong if you say those things as a teacher or as any kind of literate person. It shows that even in this modern era, You just subconsciously cannot get rid of that mentality.
@sushanthg6573
@sushanthg6573 3 жыл бұрын
Just checking upper or lower triangle is enough right, like i=1 to n, j=i+1 to n - return dp[n-1][n] (upper) or i=1 to n, j=1 to i-1 - return dp[n][n-1] (lower) ....... (solved in GFG - 100%) Anyhow, u r making our lives easy, we owe you a lot LOL - lots of love ❤ also gratitude 🙏
@chamangupta4624
@chamangupta4624 3 жыл бұрын
Bro i am watching your videos from 4 days and subscribers have increased by atleast 500 , 😁😁 placement season is approaching , do u want to give some tips regarding coding tests of companies?
@PeaceLoveAman
@PeaceLoveAman 3 жыл бұрын
last me jo output aayega usko 2 se divide bhi karna padega na ?
@kshitijgaur9635
@kshitijgaur9635 3 жыл бұрын
yess
@PeaceLoveAman
@PeaceLoveAman 3 жыл бұрын
@@kshitijgaur9635 job lag gayi ab jarurat nahi😂😂
@kshitijgaur9635
@kshitijgaur9635 3 жыл бұрын
@@PeaceLoveAman Congratulations bro!!!!
@rashmirathore6623
@rashmirathore6623 2 жыл бұрын
Nice explanation
@aniketkumarsinha2537
@aniketkumarsinha2537 3 жыл бұрын
use unordered map input the string in it with thier count.....count the number of odd counts(values) present in map and minus it with the length of string...and output will be result diveded by two
@riyaprasad5904
@riyaprasad5904 3 жыл бұрын
This won't work since the counting will not always mean that the sequence of characters is same. For eg. "ADDA" .Here "AD" and "DA" will be considered as different subsequences and the correct answer will be 1,not 2 .
@pruthvirajk6019
@pruthvirajk6019 4 жыл бұрын
Awesome..No words....
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thank you so much 😀
@iitianashishmadhukar9861
@iitianashishmadhukar9861 7 ай бұрын
great explain thanks you
@shreeniwasdeshpande6394
@shreeniwasdeshpande6394 4 жыл бұрын
I have a better sol. : make a hashmap to map characters to their count. Then ans = ans + count/2 ... here we are dividing count of each character by 2 to get the max length repeating substring . This will take O(N) time as there are only 2 iterations and also no 2d is required .
@ramabhiramabhi97
@ramabhiramabhi97 4 жыл бұрын
Bro the code using hashmap cannot gurantee about the subsequence. Correct me if i am wrong
@shashishekhar1729
@shashishekhar1729 4 жыл бұрын
it wont work try for this : ABADDBE
@apoorv7361
@apoorv7361 4 жыл бұрын
Great Explanation sir ! Can We solve this problem using auxiliary lps array which we make in KMP algo and than we can find max imum element in that lps array ??Will this approach work for this problem ??
@subhamengine1143
@subhamengine1143 2 жыл бұрын
class Solution { public: void solve(int index , int target , vectorop , vectorinput ,vector&ans ){ if(target == 0){ ans.push_back(op); return; } if(index == input.size()){ return; } vectorop1 = op; vectorop2 = op; if(target-input[index]>=0){ op1.push_back(input[index]); solve(index,target-input[index],op1,input,ans); } solve(index+1,target,op2,input,ans); } vector combinationSum(vector& candidates, int target) { vectorans; int index = 0; vectorop; solve(index,target,op,candidates,ans); return ans; } };
@SudhanshuKumar-lp1nr
@SudhanshuKumar-lp1nr 3 жыл бұрын
AC kaise hua example, qki AC me toh C repeat kr rahi hai 2:40
@YashSharma-dz7uu
@YashSharma-dz7uu 2 жыл бұрын
If you wanr to print : (Including both methods - Recursion and top-down ) #include #include #include #include #include #include using namespace std; stack st; set S; int ans(string s1, string s2, int n, int m) { if (n == 0 || m == 0) { return 0; } if (s1[n - 1] == s2[m - 1] && n != m) { return 1 + ans(s1, s2, n - 1, m - 1); } return max(ans(s1, s2, n, m - 1), ans(s1, s2, n - 1, m)); } int main() { string s1, s2; cin >> s1; s2 = s1; int l1 = s1.size(); int l2 = s2.size(); int t[l1 + 1][l2 + 1]; for (int i = 0; i
@abbas.muzammil23
@abbas.muzammil23 2 жыл бұрын
Hey, we should compare the given string itself, right? No need to reverse the given string and compare.
@shreyasvishwakarma8979
@shreyasvishwakarma8979 3 жыл бұрын
Can't we use directly UNORDERED MAP ??? We will ignore those elements which occurred only once. PLEASE CLARIFY MY DOUBT
@gautamarora6516
@gautamarora6516 3 жыл бұрын
We can do that, definitely
@KamalSharma-ep7mj
@KamalSharma-ep7mj Жыл бұрын
6:37 untouchables h? 💀
@AyushGupta-ux4gq
@AyushGupta-ux4gq Жыл бұрын
😆😆😆
@parthvasoya665
@parthvasoya665 Жыл бұрын
At 2:16, How does "AC" occur 2x times in the input "AABEBCDD"? Although "A" is there 2 times, "C" only occurs once, and by definition, we can't select the exact same set of letters for another occurrence. It also happens to violate the definition given in one of the comments (by @jain007neeraj): "Given a string, print the longest repeating subsequence such that the two subsequences don’t have same string character at same position" Here, "C" occurs at the 1st index(second character) in both cases, i.e., 'XC' and 'YC' where X and Y are two different "A" characters. Please let me know if I am missing any concept or if my assumption is wrong in any sense. Thanks in advance.
@VipulGaur3
@VipulGaur3 Жыл бұрын
He gave 'AC' just as an example, that it might have been another repeating subsequence if the string were a bit different.
@pranshunema6719
@pranshunema6719 Жыл бұрын
Completely agree.. AC doesn't follows the condition
@anshumansrivastava8108
@anshumansrivastava8108 4 жыл бұрын
so if we will remove the unique characters from the string that should do the work?
@AmitSingh-cs2hb
@AmitSingh-cs2hb 4 жыл бұрын
Nope,as in subsequence order also matters
@pranjalbansal8459
@pranjalbansal8459 4 жыл бұрын
@@AmitSingh-cs2hb I think it will work fine if we want to count the size because in counting size the order does not matters
@bharatjoshi1473
@bharatjoshi1473 4 жыл бұрын
@@pranjalbansal8459 only removing unique characters wont work becz we have to print the lenght of characters which are duplicate and they should manitain there order also for example "AABEBFCDDF" the answer will be still ABD not ABFD .
@bhushanbhosale2394
@bhushanbhosale2394 3 жыл бұрын
What if the series is ABCDDCBA the longest repeating subsequence is just DD not ABCD So will this code run?
@RajatGupta-lq3cb
@RajatGupta-lq3cb 3 жыл бұрын
won't LRS be "D" and not "DD"?
@kxnyshk
@kxnyshk 3 жыл бұрын
@@RajatGupta-lq3cb yes, only "D"
@venkatarohitpotnuru38
@venkatarohitpotnuru38 Жыл бұрын
for input abba we need to get 2 na by code i am getting 1
@Dipakjadhav
@Dipakjadhav 2 жыл бұрын
@Aditya Verma where are you? Why you are nit uploading videos?
@sehajmakkarr
@sehajmakkarr 5 ай бұрын
6:36 legendary
@kathanadalaja
@kathanadalaja 9 ай бұрын
If i want to write above recursive code every time happens tle because gfg always ask O(N^2) time complexity then what should i do?
@saurabhsen3560
@saurabhsen3560 4 жыл бұрын
I have one doubt If I am using "axxxy" as string its longest repeating subsequence should be 1 because "x" is only repeating but in geeksfoegeeks its output is 2.. HOW???
@rohitjoshi6335
@rohitjoshi6335 4 жыл бұрын
x->1 and x->2 x->2 and x->3 these are 2 subsequences
@akashutreja3233
@akashutreja3233 4 жыл бұрын
@@rohitjoshi6335 but x with index 2 can't be shared so the answer should be 1.
@rohitjoshi6335
@rohitjoshi6335 4 жыл бұрын
@@akashutreja3233 they can be shared but can't have same position in the other string.
@AshutoshSingh-qj1gm
@AshutoshSingh-qj1gm 4 жыл бұрын
www.geeksforgeeks.org/longest-repeating-and-non-overlapping-substring/ This will give the output you meant.
@akashbhoi1951
@akashbhoi1951 3 жыл бұрын
What is the ans for "aaa"?
@kanhav03
@kanhav03 3 жыл бұрын
Will it work for input such as AABBDDABD where the output should be 3 Mine giving o/p as 4
@satyalakshmiyeleti1149
@satyalakshmiyeleti1149 3 жыл бұрын
yes bcoz the ans is ABDD first lcs at index 0 2 4 5 and second lcs : 1 3 5 8 the twist here is Given a string, print the longest repeating subsequence such that the two subsequences don’t have same string character at same position
@kanhav03
@kanhav03 3 жыл бұрын
@@satyalakshmiyeleti1149 where will i find the 2nd ABDD there is only one ABDD in the string
@satyalakshmiyeleti1149
@satyalakshmiyeleti1149 3 жыл бұрын
@@kanhav03 at index 1 3 5 8 : A B D D respectively
@divineforever8691
@divineforever8691 4 жыл бұрын
well greedy will also work well , think this way the maximum times a character occurs will be length of lrs . cuz a single character too a subsequence..,but if length >1 then we need to go by dp......
@divineforever8691
@divineforever8691 4 жыл бұрын
update: i misunderstood problem:((((
@Unknown-Stranger
@Unknown-Stranger 3 жыл бұрын
@@divineforever8691 LOLOLOLOLOLOLOLOLOL
@niru1931
@niru1931 4 жыл бұрын
nice explanation
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thanks!
@035_shubhamsaurav5
@035_shubhamsaurav5 4 жыл бұрын
Great video..👍 But have a doubt that when string :axxxy how the ans:2 ??..
@akshatpandey2256
@akshatpandey2256 4 жыл бұрын
xx gives length 2
@mayankchaudhary5515
@mayankchaudhary5515 4 жыл бұрын
Answer would be 1
@AmitSingh-cs2hb
@AmitSingh-cs2hb 4 жыл бұрын
@@mayankchaudhary5515 2 aayega pagal
@0anant0
@0anant0 4 жыл бұрын
@@mayankchaudhary5515 Read Neeraj Jain's comment.
@yelp9359
@yelp9359 4 жыл бұрын
Wah bot tm 6 mhina phle hi pel diya hai isko to.
@rishabhyadav8269
@rishabhyadav8269 4 жыл бұрын
bhai yeh question toh greedy se bhi toh possible hai... we will just count number of character in the hashmap and which is greater then 1 we will count it and finally return the count. isn't it? Tell me if iam doing wrong somewhere ?
@devangrajarora7002
@devangrajarora7002 4 жыл бұрын
by your logic "caac" will give ans 2, but the answer should be 1. Whenever subsequences are involved, we shoukd consider all options, but greedy won't do that.
@bikashsah6338
@bikashsah6338 4 жыл бұрын
gazab ka explanation .......
@roushanraj8530
@roushanraj8530 3 жыл бұрын
Bhaiya aapne..... Fibonacci, LIS, kadane's , Dp on grid .....in sb pr videos ni bnai h kya .??
@ArghyaBhattacharyaNITA
@ArghyaBhattacharyaNITA 2 жыл бұрын
Bhai.. Can you arrive to the point faster. I am at 8:25 and still no sign of the solution.
@TheAdityaVerma
@TheAdityaVerma 2 жыл бұрын
Honestly if you are looking for fast quick solutions with no concepts/relation building - this is not the channel you should be watching :) That being said, I will try to keep that feedback in mind but no promises :)
@divyanshsrivastava7150
@divyanshsrivastava7150 2 жыл бұрын
@@TheAdityaVerma wohoo you are still active on this channel
@RandomShowerThoughts
@RandomShowerThoughts Жыл бұрын
if the string is just AAA, what should the answer be?
@ShubhamKumar-jd8bk
@ShubhamKumar-jd8bk 4 жыл бұрын
*Please someone tell me Why this is giving 2 for "axxxy" ?*
@kxnyshk
@kxnyshk 3 жыл бұрын
For index 1-2 and 2-3
@Pratik-Kedar
@Pratik-Kedar 4 жыл бұрын
Any one who tried printing longest palindromic substring ??
@chethan_madhu_vlogs
@chethan_madhu_vlogs 10 ай бұрын
Bro can you give solution for longest repeating substring?
@kiwimoma1799
@kiwimoma1799 6 ай бұрын
we need series for graph T.T
@ekanshgoyal6714
@ekanshgoyal6714 4 жыл бұрын
Bhai DP waali series mein LIS bhool gaya.... Wo bhi nikal de..... Yeh series dekhne ke baad to DP samaj aari :)
@harshitjain9551
@harshitjain9551 4 жыл бұрын
@Aditya Verma For AABBEBCDD its not working in this B comes thrice and giving us wrong output
@youtubecr3115
@youtubecr3115 3 жыл бұрын
He did a mistake in explain problem statement. You can take same character of string in longest repeating subsequence. See if put two same string side by side then you will observe that 'B" at thired index can be used twice. Zeroth index 'A' match with first index of second. Second index 'B' match with thired index of 'B'. Thired index 'B' match with fifth index and lastly seventh index 'D' match with eight index. You can notice in orignal string that thired index 'B' is considered twice.
@shubhamsom
@shubhamsom Жыл бұрын
Can someone explain LRS for : aabbccdefclcicd As per my calculations it should be abccd As this subsequence can be extracted 2 times, but using the dp approach I am getting "abcccc" as the result, did I misunderstand LRS and the answer should be abccc , or something is missing in this dp approach?
@ashishchawla2718
@ashishchawla2718 Жыл бұрын
The correct answer is abcccc as it's length is more than abccd. Now why abcccc is the answer is because you have 5 c's in the original string and 1 subsequence took 1,2,3,4th occurrence and the other took 2,3,4,5th occurrence so each occurrence of c is different for both the strings. I hope you understood.
@shubhamsom
@shubhamsom Жыл бұрын
@@ashishchawla2718 ohh so c1,c2 c2,c3 c3,c4 c4,c5 making 4 pairs and its possible bcz the only condition that we following is i!=j and following the ordering of subsequence, I think i got it Thanks
@sushilsingh9632
@sushilsingh9632 2 жыл бұрын
If we take an example as "ABBCA" the longest repeating subseqence has length 1 But here both A and B are repeating means has different indexes? I am little confused can somebody help me?
@devanshjha5836
@devanshjha5836 2 жыл бұрын
AB will not be a subsequence here since the order is not maintained
@ashishdas4784
@ashishdas4784 4 жыл бұрын
Nice one , but we can extract the repeating character from the LCS by using hash map if I am not wrong
@fetkamausam5132
@fetkamausam5132 3 жыл бұрын
Same thought
@vineetjain7518
@vineetjain7518 3 жыл бұрын
HashMap do not preserve the order
@sushmitagoswami2033
@sushmitagoswami2033 2 жыл бұрын
@@vineetjain7518 we can have a list of indexes in the value part of the map?
@vineetjain7518
@vineetjain7518 2 жыл бұрын
@@sushmitagoswami2033 it will throw an exception as from list an element can be removed add at any specific position therefore compile time error
@Your_Boy_Suraj
@Your_Boy_Suraj Жыл бұрын
Python Code Solution: class Solution: def LongestRepeatingSubsequence(self, str): return longestRepeatingSubsequence(str, str, len(str), len(str)) def longestRepeatingSubsequence(X, Y, n, m): dp = [[-1 for i in range(m+1)] for j in range(n+1)] for i in range(n+1): for j in range(m+1): if i==0 or j==0: dp[i][j] = 0 for i in range(1, n+1): for j in range(1, m+1): if(X[i-1] == Y[j-1] and i != j): dp[i][j] = 1 + dp[i-1][j-1] else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) return dp[n][m]
@rajaryan7576
@rajaryan7576 Жыл бұрын
Lcs of S1 & S2 will be s itself, then what is the point of finding lcs? And i==j will always be true....
@gauravraj2604
@gauravraj2604 3 жыл бұрын
what should be output of axxxy? If anyone can explain?
@ShubhamSingh-gw9kq
@ShubhamSingh-gw9kq 4 жыл бұрын
Awesome yrr!!!
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thanks brother, Do subscribe and share, that keeps me motivated to do more !!
@arpangoyal9947
@arpangoyal9947 2 жыл бұрын
We can also do these question using frequency mapping
@AmanKhandelwal07
@AmanKhandelwal07 4 жыл бұрын
What will be the answer for BAABDD
@ShubhamKumar-jd8bk
@ShubhamKumar-jd8bk 4 жыл бұрын
2 BD with index 0 and 4 second BD with index 3 and 5
@aryannijhawan8448
@aryannijhawan8448 3 жыл бұрын
have to add this to notes
@deepakbijani5495
@deepakbijani5495 10 ай бұрын
find longest palindrom length and divide it by 2
@saivamsi8400
@saivamsi8400 6 ай бұрын
No bro i think this won't work because if you consider the string "ABCKZABC" the lps is not abcabc but the longest repeating subsequence is!
@pranjalshinde1586
@pranjalshinde1586 2 жыл бұрын
What about the testcase AABXACBBCZYCC it should return ABC but as it is repeated thrice...it is returning AABBCC
@apnapython
@apnapython 2 жыл бұрын
great videos
@ankurgupta4696
@ankurgupta4696 4 жыл бұрын
but this question is not matching with the matching algorithm which we used to identify the lcs type??
@raghuwanshiaru
@raghuwanshiaru 4 жыл бұрын
At 5:20 he clearly starts demonstrating with LCS. And even towards the end, he gives the small difference in code between LCS, and LRS ( i != j is the only extra condition while checking for Longest Repeating Subsequence ).
31  Sequence Pattern Matching
10:26
Aditya Verma
Рет қаралды 140 М.
24 Shortest Common SuperSequence
22:59
Aditya Verma
Рет қаралды 203 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
32  Minimum number of insertion in a string to make it a palindrome
13:13
Longest Repeating Character Replacement - Leetcode 424 - Python
20:44
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 173 М.
I Helped 2,000 People Walk Again
15:31
MrBeast
Рет қаралды 19 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 2,4 МЛН
19  Longest common subsequence Recursive
27:42
Aditya Verma
Рет қаралды 299 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН