LIS in O(nlogn) with printing solution | Day 4 Part 1 | Dynamic Programming workshop | Vivek Gupta

Поділитися
Вставка
  • Опубліковано 15 січ 2025

КОМЕНТАРІ • 69

  • @Live-hh6li
    @Live-hh6li 2 роки тому +27

    I have never seen such an amazing explanation of Lis in nlogn.
    Other YT videos just explain that you have to make an array and make an upper bound and replace, and the size of the vector will be lis.
    But the thinking behind it, that it will (Len,last) is something that I can remember and even if I don't remember the algo, just this idea of (Len,last) will be enough to write entire code.
    Thanks a lot Vivek.

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

    The world need educators like you

  • @tusharsingh9346
    @tusharsingh9346 5 місяців тому +2

    i feel good someone actually teaching , not spoon feeding , not teaching as it a trick and we need to mug that up. Every other even big channel teaching tricks to solve qn. thank for high quality education .

  • @AdityaSingh-uh9lq
    @AdityaSingh-uh9lq Місяць тому +2

    This is such a great explanation for such a complex thing, you are doing a great job man, please keep helping us!

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

    First time completely understood lis in nlogn! Although randomly opened the video, planning to watch all the DP

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

    Thanks for the great explanation, I earlier read several blogs regarding printing in O(NlogN), but none of them I was able to understand completely. You made it looked so simple.
    Thanks a lot.

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

    never seen printing lis in nlogn. such a unique idea. thank you vivek bhaiya.

  • @khushi8923
    @khushi8923 5 місяців тому

    the best explanation for LIS over the whole internet

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

    The best DSA /CP teacher , period.

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

    No words to describe! Just thank you very much.

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

    Wao 🔥

  • @vaibhavvaddoriya1269
    @vaibhavvaddoriya1269 7 місяців тому

    It is an amazing explanation for printing LIS in NlogN.

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

    What is form of optimised one? Not looking like Form 2 na

    • @vivekgupta3484
      @vivekgupta3484  Рік тому +3

      its form 2 only … but the saved value is different… its lowest value ending with length x.

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

    Also we can observe that when we print the partial solution, the first solution for a particular length is the actual lis of the length. We can see 1, 5, 6, 7, 9 printed in the partial solutions also thats the first time 9 was inserted and after that we were not able to increase the lis, so the sequence in which 9 was inserted at the end is the lis.

    • @hemanggautam7473
      @hemanggautam7473 Місяць тому

      I think it is wrong.Consider a 10 at the last element of the example which Vivek took. Clearly first partial solution of length 6 is 1 2 3 7 9 10 which is not actual LIS

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

    Thank you for the way you have explained the solution..

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

    Beautiful idea and beautiful explanation too... 🔥🔥🔥

  • @ravirajawasthi
    @ravirajawasthi 8 днів тому

    Really good explanation

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

    Thank you!! Very helful

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

    A stressed day today. But finally watched it.

  • @Sandeep-zd6dq
    @Sandeep-zd6dq 2 роки тому

    At 13:30, I think for length 4 the best will be ending at 8 instead of 9 because last is smaller in case of 8 (1,5,7,8)

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

      Till that time we have not seen the 8... and its the older 9.

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

    Simple is hard--Martin scorcese...outstanding explanation

  • @sumedhiscoding
    @sumedhiscoding 9 місяців тому

    Sir the backpointers you keep mentioning any hope that we will get to see what that actually is ? Thanks a lot for this wonderful lecture!!! Always a blessing to watch your lectures

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

    🛐

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

    🔥🔥

  • @JilSharma
    @JilSharma 6 місяців тому

    wow great algorithm 🙂

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

    Like this..also make a workshop on graph and trees..as there are very less quality content available regarding it.

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

    Tanks for amazing explanation. When you are going to upload day-6 videos. Waiting for it .

  • @noone0978
    @noone0978 5 місяців тому

    sir if we get configuration like this in insertedat array - 1 2 3 4 3 5, then we also we will have same answer with just different elements, isn't it?

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

    cool :)

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

    👑 orz

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

    what if we have to print the lexicographically smallest LIS

  • @charlesdingus9662
    @charlesdingus9662 6 місяців тому

    Hi Vivek, can the lexographically smallest LIS be printed in O(NlogN)?

    • @vivekgupta3484
      @vivekgupta3484  6 місяців тому

      Yes. Thats another beautiful problem in itself.

    • @charlesdingus9662
      @charlesdingus9662 6 місяців тому

      @@vivekgupta3484 can you give a little hint on how to approach it.

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

      ​@@charlesdingus9662 this is already that one u r talking about , as we are traversing from back and picking the last element at that length , it's already the smallest updated one ...7

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

    my idea for bitonic is that we keep 2 vector which holds the BEST LIS at each index and the other vector holds the best LDS at each index and we will sum the corresponding indexes together but decrease 1 to not over count. maybe we don't need function LDS we can use the same LIS but we need to reverse it and we need to keep track of each element original index which is (N - new_index_after_reverse) Is this right ? I did try it and it seems correct

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

      Yup thats correct.

    • @dank7044
      @dank7044 6 місяців тому

      I think there's still a caveat, suppose best possible length till index x = 6, and its ending element is 7, and the best possible length of LDS till x is 8 but it last ending eleemnt is 8, in that case we simply add the lengths,we only do -1,if both of them have same last ending element.

    • @DayaTapuKPapaGada
      @DayaTapuKPapaGada 6 місяців тому

      ​@@dank7044lis we are keeping from beginning and lds from last and also they are ending at same position so how can their values be different?

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

    🔥🔥🔥🔥🎇🎇❤️

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

    Have anyone taken yesterday doubt session
    It is not in videos of this channel

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

      He didnt took that yesterday. Maybe something imp. came up.

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

      @@priyanshsinghal9977 Thanks for the clarification Brother.

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

      @@priyanshsinghal9977 Not in my best health.. Will try to take it today.

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

      @@vivekgupta3484 Take care. I wish you a healthy life.

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

    Thanks for the explanation, I own figured out another way to print LIS from the observation in this video.
    What I did, I stored the first vector formed with x length and returned the vector corresponding to vec.size() after the iteration using map.
    I know the space is much higher than the explanation in the video but still it's another way to print LIS.
    🙂🙂

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

    can you please do it in java too?

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

      i think most of the code portions are same.

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

      ​@@vivekgupta3484that lower_bound i cant see in java

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

    Can you please solve the Maximum Square Matrix (Day3 Question 3) using recursion and memoisation

  • @RajGupta-cu9hi
    @RajGupta-cu9hi Рік тому

    Insertion sort 😮

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

    Help!!
    Finding the longest bitonic sequence in n^2 complexity is easy we can do dp1[i] + dp2[i] - 1, where dp1 is LIS and dp2 is the longest decreasing subsequence. I cannot understand how to achieve this in O(nlogn) complexity. Do we have to increase the number of states in order to achieve this? Thanks in advance

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

      calculate dp1 and dp2 in nlogn maybe?

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

      @@vivekgupta3484 The insertedAt array although stores the size at which every element was inserted but also stores the best possible answer for every index i, which is basically the same as dp. Is this correct?

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

      @@sanketpoojari6057 the index where ith element gets inserted is dp[i].

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

      @@vivekgupta3484 Thanks, that was very helpful. Btw, this series is very good❤

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

    attendance ++

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

    I print the LIS using the upper_bound, it is giving the right answer but please check whether it is valid
    here lastIndex is the index in arr of last element in the lis vector(here last element is 9, so lastIndex is 7)
    for(int i=lastIndex;i>=0;i--){
    if(finalLIS.empty() || finalLIS.back()>arr[i]){
    finalLIS.push_back(arr[i]);
    }
    else{
    auto it=upper_bound(finalLIS.begin(), finalLIS.end(),arr[i]);
    }
    }
    reverse(finalLIS.begin(),finalLIS.end());

  • @Ramu9119
    @Ramu9119 5 місяців тому

    +1

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

    Watch twice if u don't get at once...

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

    🤔🥴😵‍💫Printing part is hard to get

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

      True... try to take a input and run the idea on it.

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

      @@vivekgupta3484 Yes will do that, thanks for your efforts 👍

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

    Great!!!