30 Longest repeating subsequence

Поділитися
Вставка
  • Опубліковано 4 лют 2020
  • Longest Repeating Subsequence
    Given a string, print the longest repeating subsequence such that the two subsequence don’t have same string character at same position, i.e., any i’th character in the two subsequences shouldn’t have the same index in the original string.
    Example:
    Input: str = "aab"
    Output: "a"
    The two subsequence are 'a'(first) and 'a'
    (second). Note that 'b' cannot be considered
    as part of subsequence as it would be at same
    index in both.
    PROBLEM STATEMENT LINK:www.geeksforgeeks.org/longest...
    Playlist Link: • Dynamic Programming | ... .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

КОМЕНТАРІ • 353

  • @eren-qu9uu
    @eren-qu9uu 3 роки тому +145

    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.

  • @nikhilraj5115
    @nikhilraj5115 4 роки тому +303

    Bro ,do you have any plan to publish the series on "graph".

    • @Prince-fz6yo
      @Prince-fz6yo 3 роки тому +13

      @OttoLyle @Mauricio Weston.. u both seems to be of same mother but diff fathers

    • @tushargupta6336
      @tushargupta6336 3 роки тому

      no

    • @RuinsOfTheUnknown
      @RuinsOfTheUnknown 3 роки тому +3

      @@Prince-fz6yo 😂😂😂😂

    • @arafatkhan5489
      @arafatkhan5489 3 роки тому +4

      @@maharajak6578 bhai this weston dude's comment got deleted ig, what did he say tho?

    • @SHASHANKRUSTAGII
      @SHASHANKRUSTAGII 3 роки тому +3

      @@arafatkhan5489 haha i also didnt get

  • @jain007neeraj
    @jain007neeraj 4 роки тому +117

    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 3 роки тому

      Case :- AABCABB
      ANS :- 5
      This question is little bit confusing read it twice if anyone is confused.

    • @DeepakKumar-yl3ok
      @DeepakKumar-yl3ok 3 роки тому +11

      @@hemantmangwani1006 The answer should be 4 for the string "AABCABB" not 5

    • @koustav6884
      @koustav6884 3 роки тому +1

      @@DeepakKumar-yl3ok yes

    • @bhaswatraj9433
      @bhaswatraj9433 3 роки тому

      RAJ Kumar why is it not 3

    • @koustav6884
      @koustav6884 3 роки тому +1

      @@bhaswatraj9433 No answer will be four you can cross check it by applying on algorithm

  • @mukeshranjanmallick8832
    @mukeshranjanmallick8832 3 роки тому +13

    Whole Series is just awesome , Great explanation and thought process

  • @HarpreetSingh-mb2rk
    @HarpreetSingh-mb2rk Рік тому +3

    literally the logic of this problem comes to my mind automatically after watching your DP playlist.

  • @ankitbhardwaj9566
    @ankitbhardwaj9566 4 роки тому +68

    please make more videos on weighted graphs ,shortest paths ,prim ,krushkal ,,from codeforces

  • @AJ-gg1jc
    @AJ-gg1jc 3 роки тому +10

    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.

  • @shritvaagarwal614
    @shritvaagarwal614 3 роки тому +2

    Simply Genius!!...........Please bring graph series too

  • @0anant0
    @0anant0 3 роки тому +85

    29 of 50 (58%) done! Very nicely done!

    • @pr1493
      @pr1493 2 роки тому +20

      It doesn't mean that you achieved something here, hold back and practice

    • @prateekchauhan5376
      @prateekchauhan5376 2 роки тому +12

      @@pr1493 if u cant support, atleast don't be toxic

    • @pr1493
      @pr1493 2 роки тому +3

      @@prateekchauhan5376 Just tried to push that guy to practice more without getting complacent, Don't know what ails you here lol 😂

    • @deepakpandey3485
      @deepakpandey3485 Рік тому

      @@pr1493 jada cool mat ban bhai... tune kya kiya you also know it.

    • @pr1493
      @pr1493 Рік тому

      @@deepakpandey3485 We can talk when you have a job

  • @oaarian2014
    @oaarian2014 2 роки тому +6

    untouchables ..dank bhai😂😂

  • @Rohan-vl1ve
    @Rohan-vl1ve Рік тому

    Thank you bro, you have great teaching and explaining skills

  • @shivanidalmia2623
    @shivanidalmia2623 4 роки тому +88

    Can you make a video on Longest Increasing subsequence.

    • @anandabhinav
      @anandabhinav 3 роки тому +21

      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 3 роки тому +2

      @@anandabhinav If there will be repitition in array it will give wrong ans

    • @anandabhinav
      @anandabhinav 3 роки тому

      @@maximus6448 bro binary search wala approach use karrlenge phirr.

    • @VIVEK1898
      @VIVEK1898 3 роки тому +1

      @@yashbhanushali8456 remove duplicates from the sorted array.

    • @VIVEK1898
      @VIVEK1898 3 роки тому +1

      @@anandabhinav remove duplicated from sorted array

  • @travellingsLenses
    @travellingsLenses 2 роки тому +1

    Amazingly explained bro. Itne easy-going flow me samjhaya hai ki Binge watching chal rhi hai :D

  • @nikhilranjan7126
    @nikhilranjan7126 3 роки тому +1

    Awesome content I am waiting for more such videos... your explanation is good.

  • @vakhariyajay315
    @vakhariyajay315 Рік тому +2

    Thank you very much. You are a genius.

  • @sushanthg6573
    @sushanthg6573 2 роки тому

    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 2 роки тому +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

  • @lalit2926
    @lalit2926 3 роки тому +10

    Oh !! my bad, both strings are equal😂😂 @5:50 ..
    ..
    ..
    By the way your DP tutorial is best sir❤❤..

  • @g1patil
    @g1patil 2 роки тому +2

    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 !!

  • @apoorv7361
    @apoorv7361 3 роки тому +2

    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 ??

  • @Education_2753
    @Education_2753 3 роки тому +4

    Sir plz complete this playlist of dynamic programming
    It's humble request sir plz
    Upload the video sir as soon as possible

  • @saranghae3720
    @saranghae3720 2 роки тому +7

    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 Місяць тому

      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

  • @vladimirputin2756
    @vladimirputin2756 10 місяців тому +2

    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);
    }
    }

  • @dhruvagarwal646
    @dhruvagarwal646 3 роки тому +2

    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.

  • @saurabhmodi5128
    @saurabhmodi5128 2 роки тому

    best explanation of the Longest repeating subsequence

  • @siddheshjain8677
    @siddheshjain8677 3 роки тому +3

    This was a very good question solved in an easiest manner ever!

  • @sanyamsinghal7992
    @sanyamsinghal7992 4 роки тому +29

    lovely explanation!! great work man ♥♥
    please also make videos on graph topics like BFS, DFS and Shortest path.

    • @TheAdityaVerma
      @TheAdityaVerma  4 роки тому +37

      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 роки тому +6

      @@TheAdityaVerma next video kab aayega bhaiya??

    • @krishnasai3367
      @krishnasai3367 2 роки тому +11

      @@TheAdityaVerma its been more than a year, still no videos on graphs 😔😭

    • @Vishal-ds6ly
      @Vishal-ds6ly Рік тому +2

      @@TheAdityaVerma its been than 2 year, still no videos on graphs.

    • @sidhantjha4566
      @sidhantjha4566 Рік тому +2

      @@TheAdityaVerma We Want Graph Series.

  • @chamangupta4624
    @chamangupta4624 2 роки тому +2

    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?

  • @pawankumarpandit1822
    @pawankumarpandit1822 Рік тому

    thank you aditya bhaiya because of you i am able to solve the different kind of question

  • @oqant0424
    @oqant0424 2 роки тому

    Amazing Explanation🙌🙌

  • @kathanadalaja
    @kathanadalaja 3 місяці тому

    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?

  • @shreeniwasdeshpande6394
    @shreeniwasdeshpande6394 3 роки тому +1

    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 3 роки тому +3

      Bro the code using hashmap cannot gurantee about the subsequence. Correct me if i am wrong

    • @shashishekhar1729
      @shashishekhar1729 3 роки тому +2

      it wont work try for this : ABADDBE

  • @pranjaltiwari2344
    @pranjaltiwari2344 4 роки тому +5

    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 3 роки тому

      Ya you are right.

    • @ayansrivastava722
      @ayansrivastava722 Рік тому

      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.

  • @samarthbhawsar8739
    @samarthbhawsar8739 2 роки тому +3

    Amazing Explanation🙌🙌
    It's just like a magic happened in every video..👏👏🔥🔥

  • @samyakjain720
    @samyakjain720 4 роки тому +2

    Bhai u made dynamic programming like sweet

  • @aniket6858
    @aniket6858 Рік тому +2

    Bro we got AABBDD on taking all these conditions in mind.. shouldn't we do half of it to get final answer??

  • @pruthvirajk6019
    @pruthvirajk6019 4 роки тому +6

    Awesome..No words....

  • @sumitkumar-oi5vq
    @sumitkumar-oi5vq 3 роки тому +10

    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 3 роки тому +7

      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 3 роки тому +6

      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.

  • @iitianashishmadhukar9861
    @iitianashishmadhukar9861 25 днів тому

    great explain thanks you

  • @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
    }

  • @rahulagarwal4358
    @rahulagarwal4358 3 роки тому +2

    Input: str = "axxxy"
    Output: 2
    Why above has output as 2(XX).

    • @tanay238
      @tanay238 3 роки тому +2

      index 2,3 and index 3,4 ... one X is overlapping

  • @gauravraj2604
    @gauravraj2604 3 роки тому

    what should be output of axxxy? If anyone can explain?

  • @rashmirathore6623
    @rashmirathore6623 2 роки тому

    Nice explanation

  • @anshumansrivastava8108
    @anshumansrivastava8108 4 роки тому +3

    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 3 роки тому

      @@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 3 роки тому +1

      @@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 .

  • @rahulchudasama9363
    @rahulchudasama9363 3 роки тому +6

    Hi Aditya,
    Big thank you,
    Can you please make a playlist of the graph ???

  • @aayush1204
    @aayush1204 3 роки тому +26

    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 2 роки тому +2

      Have you found any series like this for dp on grids, lis Or even understandable in yt pls suggest me 😔

    • @lovedeepsingh120
      @lovedeepsingh120 2 роки тому +1

      @@thinkingmad1685 Watch Striver's DP playlist for these topics. He explained all of them very well..

  • @niru1931
    @niru1931 4 роки тому +2

    nice explanation

  • @arpangoyal9947
    @arpangoyal9947 Рік тому

    We can also do these question using frequency mapping

  • @divineforever8691
    @divineforever8691 3 роки тому

    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......

  • @harshitjain9551
    @harshitjain9551 3 роки тому

    @Aditya Verma
    For AABBEBCDD its not working
    in this B comes thrice and giving us wrong output

    • @youtubecr3115
      @youtubecr3115 3 роки тому +1

      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.

  • @princenagar1686
    @princenagar1686 3 місяці тому

    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.

  • @kanhav03
    @kanhav03 3 роки тому +1

    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 роки тому +1

      @@kanhav03 at index 1 3 5 8 : A B D D respectively

  • @shubhamsom
    @shubhamsom 10 місяців тому

    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 6 місяців тому

      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 6 місяців тому

      @@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 роки тому +1

      AB will not be a subsequence here since the order is not maintained

  • @abhi-5783
    @abhi-5783 4 роки тому +38

    "Untouchables hai, nahi hai...". Lol

  • @samriddhashukla5345
    @samriddhashukla5345 3 роки тому

    bhai chota sa question itna complicate kiya aapne maza aa gya

  • @aniketkumarsinha2537
    @aniketkumarsinha2537 3 роки тому +4

    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 2 роки тому +24

      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 .

  • @shreyasvishwakarma8979
    @shreyasvishwakarma8979 2 роки тому +1

    Can't we use directly UNORDERED MAP ??? We will ignore those elements which occurred only once. PLEASE CLARIFY MY DOUBT

  • @AkashKumar-vc5yl
    @AkashKumar-vc5yl 2 роки тому +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.

  • @SilentNight_Tour
    @SilentNight_Tour Рік тому

    MZA AA GYA DP SEIES SIR

  • @devvats8353
    @devvats8353 3 роки тому

    cant we do this by using simple hashing ??.if any of the index is greater than 1 then we add 1 in our answer ? correct me if im wrong

  • @Dipakjadhav
    @Dipakjadhav 2 роки тому

    @Aditya Verma where are you? Why you are nit uploading videos?

  • @rishabhyadav8269
    @rishabhyadav8269 4 роки тому +1

    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 роки тому +15

      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 .......

  • @paritoshdadhich2954
    @paritoshdadhich2954 3 роки тому

    Thank you bhaiya

  • @abbas.muzammil23
    @abbas.muzammil23 Рік тому

    Hey, we should compare the given string itself, right? No need to reverse the given string and compare.

  • @bhushanbhosale2394
    @bhushanbhosale2394 3 роки тому +2

    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 роки тому +2

      won't LRS be "D" and not "DD"?

    • @kxnyshk
      @kxnyshk 2 роки тому

      @@RajatGupta-lq3cb yes, only "D"

  • @ngtv5608
    @ngtv5608 3 роки тому +12

    Need a playlist on GRAPH !!

    • @rhythemjain1067
      @rhythemjain1067 2 роки тому +1

      You should try Striver's Graph series. It really helped me in clearing my concepts.

  • @ashishdas4784
    @ashishdas4784 3 роки тому +1

    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 2 роки тому +4

      HashMap do not preserve the order

    • @sushmitagoswami2033
      @sushmitagoswami2033 Рік тому

      @@vineetjain7518 we can have a list of indexes in the value part of the map?

    • @vineetjain7518
      @vineetjain7518 Рік тому

      @@sushmitagoswami2033 it will throw an exception as from list an element can be removed add at any specific position therefore compile time error

  • @hustler516
    @hustler516 2 роки тому +1

    Bhaiya lol to ur teaching 🥰 ......who else wants to say the same lines to bhai with me

  • @ShubhamSingh-gw9kq
    @ShubhamSingh-gw9kq 4 роки тому +5

    Awesome yrr!!!

    • @TheAdityaVerma
      @TheAdityaVerma  4 роки тому +5

      Thanks brother, Do subscribe and share, that keeps me motivated to do more !!

  • @ShivamSharma-bb1jx
    @ShivamSharma-bb1jx 3 роки тому +1

    faad diya bro faad diya.....!!

  • @AMITKUMAR-ze9yo
    @AMITKUMAR-ze9yo 3 роки тому +2

    thanks buddy :) , @5:50 leaving 'e' while finding LCS of same string was funny though :D

  • @PeaceLoveAman
    @PeaceLoveAman 3 роки тому +3

    last me jo output aayega usko 2 se divide bhi karna padega na ?

  • @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;
    }
    };

  • @ShubhamKumar-jd8bk
    @ShubhamKumar-jd8bk 3 роки тому +1

    *Please someone tell me Why this is giving 2 for "axxxy" ?*

    • @kxnyshk
      @kxnyshk 2 роки тому

      For index 1-2 and 2-3

  • @akashbhoi1951
    @akashbhoi1951 2 роки тому +1

    What is the ans for "aaa"?

  • @aryannijhawan8448
    @aryannijhawan8448 2 роки тому

    have to add this to notes

  • @ankurgupta4696
    @ankurgupta4696 4 роки тому

    but this question is not matching with the matching algorithm which we used to identify the lcs type??

    • @raghuwanshiaru
      @raghuwanshiaru 3 роки тому

      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 ).

  • @035_shubhamsaurav5
    @035_shubhamsaurav5 4 роки тому +2

    Great video..👍
    But have a doubt that when string :axxxy how the ans:2 ??..

  • @pranjalshinde1586
    @pranjalshinde1586 2 роки тому

    What about the testcase AABXACBBCZYCC
    it should return ABC but as it is repeated thrice...it is returning AABBCC

  • @RandomShowerThoughts
    @RandomShowerThoughts Рік тому

    if the string is just AAA, what should the answer be?

  • @sharuk3545
    @sharuk3545 3 роки тому

    Bro make a playlist on Graph.

  • @apnapython
    @apnapython 2 роки тому

    great videos

  • @amarnathprasad9986
    @amarnathprasad9986 2 роки тому +5

    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 2 роки тому

      I will too drop right now in 5th sem... Preparing for interviews too

    • @kxnyshk
      @kxnyshk 2 роки тому

      how did they go?

    • @amarnathprasad9986
      @amarnathprasad9986 2 роки тому +2

      @@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 2 роки тому

      @@amarnathprasad9986 that's amazing. Congrats!

    • @amarnathprasad9986
      @amarnathprasad9986 2 роки тому

      @@kxnyshk Thanks!

  • @saurabhsen3560
    @saurabhsen3560 4 роки тому +5

    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 роки тому +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 роки тому +11

      @@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.

  • @roushanraj8530
    @roushanraj8530 3 роки тому

    Bhaiya aapne..... Fibonacci, LIS, kadane's , Dp on grid .....in sb pr videos ni bnai h kya .??

  • @Pratik-Kedar
    @Pratik-Kedar 3 роки тому +1

    Any one who tried printing longest palindromic substring ??

  • @manishakanyal751
    @manishakanyal751 3 роки тому

    can someone explain to me, what will be the lrs of axxxy?

    • @037_sayedramishali7
      @037_sayedramishali7 3 роки тому

      I think 1 and that will be "x"

    • @kxnyshk
      @kxnyshk 2 роки тому

      1st sub-seq : "x x" at Index : 1-2
      2nd sub-seq: "x x" at index : 2-3
      so length = 2;

  • @abhishekverma7604
    @abhishekverma7604 Рік тому

    understood!!

  • @ShivamKumar-cv7jv
    @ShivamKumar-cv7jv 3 роки тому +4

    we can also use map for this and make the complexity of O(m+n), and by the way i am fond of your videoes..

    • @HimanshuKumar-xz5tk
      @HimanshuKumar-xz5tk 3 роки тому +2

      Indexes matter in subsequences, lets say u have a string abbbbbbcca. If you just store count of all values, probably u will get abc as answer but abc is occurring only once here.

    • @Kaivalyamani
      @Kaivalyamani 3 роки тому +1

      @@HimanshuKumar-xz5tk but correct answer will be bca

    • @fightstressdepressionwithm3934
      @fightstressdepressionwithm3934 2 роки тому

      @@Kaivalyamani No, only bbbc

  • @k.chandanapriya4004
    @k.chandanapriya4004 3 роки тому +1

    bhaiya graphs par bhi videos banao... please

  • @adityadev2825
    @adityadev2825 4 роки тому +1

    Awesome

  • @venkatarohitpotnuru38
    @venkatarohitpotnuru38 6 місяців тому +1

    for input abba we need to get 2 na by code i am getting 1

  • @yashpreetbathla4653
    @yashpreetbathla4653 4 роки тому

    awesome bro ! thank you very much :))

  • @anshulgoel1940
    @anshulgoel1940 11 місяців тому

    Can't we just put each index in a map where key is the letter. Now for all those letters which have more than one entry in increasing order will be the answer. This will be like linear complexity

  • @baravkarnishithjagdish-iii5945
    @baravkarnishithjagdish-iii5945 2 роки тому

    what a great question

  • @ekanshgoyal6714
    @ekanshgoyal6714 3 роки тому +1

    Bhai DP waali series mein LIS bhool gaya....
    Wo bhi nikal de.....
    Yeh series dekhne ke baad to DP samaj aari :)

  • @rahulsrivastav9259
    @rahulsrivastav9259 3 роки тому

    if input = "AAA" it's output should be "A" but it is giving "AA" .please explain

    • @lohityakumarambashta3921
      @lohityakumarambashta3921 3 роки тому

      @Aditya Dalvi But if we take 2 A's in 1st subsequence, then we are left with only one A. The repeating subsequence cannot contain a letter at same index. Please Clarify. The output should be only 'A'

    • @tanujabharti8043
      @tanujabharti8043 3 роки тому +6

      @@lohityakumarambashta3921 in the first subsequence "AA" index of first A is 0 and index of second A is 1
      whereas in the second subsequence "AA" index of first A is 1 and the index of second A is 2......read twice, position matters, the position of the first index of both subsequences are different(0 and 1) and position of the second index of both subsequences are different(1 and 2).
      AA
      01
      AA
      12
      I hope this helps you:)

  • @funenjoynilaypatel4553
    @funenjoynilaypatel4553 Рік тому +1

    17 SEP 2022