Longest increasing subsequence

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

КОМЕНТАРІ •

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

    You must be very proud of yourself for creating such great contents. Thanks. You are a big help. Keep up the good work. Our community needs you.

  • @amanrai8010
    @amanrai8010 4 роки тому +8

    You are very interactive with us despite having a good number of views you make sure to clear each and everyone's doubt. Thank you.

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

    at 7:16, "If you think about it, you will get it yourself". Instead of calling out names of variables, arrays and reading out every number in the array, time should be spent wisely to explain the "intuition" behind the logic - That's more important than syntax.

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

    Others explained how.....
    You explained how + why - That's great

  • @fanigo138
    @fanigo138 3 роки тому +24

    Great explanation! Please upload the o(N*logN) approach.

  • @jaswantrohila3776
    @jaswantrohila3776 4 роки тому +8

    UA-camrs have made soo much buildup for this problem 😂.....but you killed it man...🔥🔥 Thanks

  • @dev-skills
    @dev-skills 3 роки тому +22

    Great to see you also covered the variation of this problem where we need to return the subsequence itself instead of longest subsequence length.

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

    I got up at 5:30 to watch your videos lol... I love it, you explained it so well, I don't think I will ever forget about this solution. I didn't get it out myself cause I was stuck trying to get it in constant time and then I couldn't. Some DP can be done using linear some has to use N^2. So sometimes I got stuck not knowing how to think of the best solution. There's a follow up question to prove it to O(n log(n)) time as well. ehhh, binary search again.

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

      5:30! ❤️ Please explain me NlogN solution. Wanna learn it from you :)

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

      @@techdose4u Let me try to figure it out and I will teach you 🤣🤣

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

      @@yitingg7942 Thanks ❤️ I am waiting for it 😀

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

      @@techdose4u I tried Surya, I just couldn't understand the binary search solution nor the binary search code itself.

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

      Okay. Then I will try to explain you now :)

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

    Thank bro. I was just worried about the length of video. But now it doesn't matter.

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

    Recursion with Memoization time complexity is also O(n^2)

  • @MohitKumar-ub2td
    @MohitKumar-ub2td 5 років тому +4

    One of the best explanation of this topic i have seen on UA-cam.
    Keep going man and your way of teaching the concept is too good and also you make it easy to understand...

    • @techdose4u
      @techdose4u  5 років тому

      Thanks :)

    • @MohitKumar-ub2td
      @MohitKumar-ub2td 5 років тому +1

      You deserve it, honestly speaking i merely write anything but when someone makes such content then i can't stop myself because my inner soul says that this man has putting lots of hard work for making such content and futher it helps a lots of students.....

    • @MohitKumar-ub2td
      @MohitKumar-ub2td 5 років тому

      Also please make more and more videos...

    • @techdose4u
      @techdose4u  5 років тому +5

      I do take out time on weekend for teaching. That's my hobby :)

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

    Nice Explanation! I think its very difficult to solve this problem in interview with out prior knowledge of this approach.

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

    Explanation is clear as a crystal ⭐⭐

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

    What to say this series is just amazing ❤️

  • @spetsnaz_2
    @spetsnaz_2 5 років тому +2

    never thought that you would make this problem soooooo ezzzzzyyyyy.....😍😍😍

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

    Thank you sir for creating such great content and helping us building our concepts.

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

    class Solution:
    def lis(self, A):
    res = [A[0]]
    n = len(A)

    for num in A[1:]:
    if num>res[-1]:
    res.append(num)
    else:
    res[bisect_left(res,num)] = num
    return len(res)

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

    really good explanation..but it would be more helpful if you also start with recursive approach and slowly convert it into a dp..if video length if the problem you can make it in parts..it would be more helpful for beginners like me to solve dp problems.... Overall a very good explanation..

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

      Yep. I will make that from further videos :)

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

    For the variation. If we have array as 10, 5, 11, 6, 9
    Here the lis array would look like: 1, 1, 2, 2, 3
    But when we trace back for string of longest increasing subsequence then as said the array would go by taking 9 , then we could either take up 6 or 11, but taking 11 would be wrong subsequence.
    I dont know if I am missing something. Though thanks for the explanation.

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

      We can probably add a condition where arr[i] < top of the stack if we are storing the values of the subsequence in the stack. Hope this helps

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

    nice explanation. Thankx a lot for this.
    KEEP IT UP!!.

  • @ANKURSingh-yl2lj
    @ANKURSingh-yl2lj 4 роки тому +8

    can u make a video for this problem in O(nlogn) complexity by using dp+binarysearch by the way ur explanation is brilliant ur voice quality and picture quality is great thanx fr this type of help

    • @techdose4u
      @techdose4u  4 роки тому +7

      Welcome. I will try in future as I get time.

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

      @@techdose4u still waiting for this video =]]

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

    Best explanation from basic to very next level. Awesome 👌👌🔥🔥

  • @dev-skills
    @dev-skills 3 роки тому +1

    1:45 subarray (not substring as we have integers not characters)

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

    There is a binary search approach also which is O(nlogn)

  • @dev-skills
    @dev-skills 3 роки тому

    Solution to this problem and its limitations using Backtracking approach very well explained and was also very to the point.

  • @PankajKumar-ft7lc
    @PankajKumar-ft7lc 5 років тому +15

    second part(finding the sub sequence) is wrong.
    what if the arr is [99,100,1,2,101,3]
    then lis array will be [1,2,1,2,3,3]
    now according to you LIS should be 1,2,3 or 99,2,3 or 99,100,3 or 1,2,101 or 99,2,101 or 99,100,101.
    and many of these are wrong.
    Please correct me if I am wrong or I miss understood anything.

    • @techdose4u
      @techdose4u  5 років тому +7

      Well, the thing which i did not tell is, you will keep comparing corresponding values in your original array before making a concrete decision of choosing a lower value as a LIS subsequence. If you don't compare corresponding elements in original array then there is no way to know the correct answer. Thanks for highlighting this imp point.

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

      How to write logic for it , can u explain?

  • @AhamedKabeer-wn1jb
    @AhamedKabeer-wn1jb 3 роки тому

    Amazing Sir..superb Explanation..

  • @AmanKumar-ht8xi
    @AmanKumar-ht8xi 5 років тому +8

    please make videos on some of the questions of "must do interview preparation" from geeksforgeeks.. because it has quality questions and solution is not available on youtube.. by the way your explanation is just awesome.. thank you for the videos

    • @techdose4u
      @techdose4u  5 років тому +7

      That's my objective too. I will be covering the most important questions in coming 6 months.

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

      @@techdose4u Thanks.
      Your videos are really soo helpful.

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

      @@techdose4u Yes please do that. You are helping the community.

  • @9-1939
    @9-1939 2 роки тому

    💯 superb explanation

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

    When I paused to think, I solved it differently. I sorted the elements, then applied uncrossed line (LCS). It is giving same answer.

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

    That's a really clear explanation ...Great

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

    You are really amazing, the best video for this question

  • @DeepikaaSelvam
    @DeepikaaSelvam 2 місяці тому

    You nailed it man!!!🥰

  • @Shakib.Siddiqui
    @Shakib.Siddiqui Рік тому

    Great what a good explanation and solution

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

    Nice explanation. Can you please make an explanation video for the optimal method using DP with binary search as well? It has n Log n time complexity. Also ,came across another problem asking us to find number of longest increasing subsequences. If you could explain on that ,it will be a great help as well .

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

    I came across a question, which I feel is similar to LIS. Problem statement : find the longest subsequence, such that the XOR of adjacent elements in the subsequence is equal to a given ‘k’ value. Please throw some light on this problem statement.

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

    We can sort the sequence and find lcs of the sorted and original array.. i guess it will also work here...

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

    16:39 for getting the subsequence array

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

    Bro you are superb. Apart from uploading coding videos. Please try to make videos on general topics while preparing for interviews like how to dry run the code effectively etc.

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

      Good idea....but this can only be done from the next month as I am busy with leetcod this month.

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

      @@techdose4u okay bro

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

      @@techdose4u Bro if I just practice the most popular 30-40 questions of each topic , will it be enough to crack interviews?

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

      Yes.... That should be enough.... Provided you keep practicing and keep learning

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

      @@techdose4u ok bro

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

    very beautifully explained..the hardest concept

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

    Please also cover the O(nlogn) TC approach

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

    Wow !! Really Awesome Dude.

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

    code of Above logic : LEETCODE 300
    public static int lengthOfLIS(int[] nums) {
    int[] lis = new int[nums.length];
    // each element itself is an increasing sub sequence
    for (int i = 0; i < lis.length; i++) {
    lis[i] = 1;
    }
    for (int i = 0; i < nums.length; i++) {
    for (int j = 0; j nums[j] && lis[i] max) {
    max = Math.max(max, lis[i]);
    }
    }
    return max;
    }

  • @Rasheed21
    @Rasheed21 4 місяці тому

    updating of the LIS should be a max of the new value and the current value for example, using Java: LIS[i] = Math.max(LIS[i], LIS[j] + 1);

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

    Can you cover the solution with n(log n) complexity?

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

    clearly explained. thanks.
    btw one suggestion, if you could explain the memoization technique after the recursion it would be great lesson.
    recursion -> recursion + memoization -> DP -> DP(nlogn version) in that order would be a great help for the learners to catch the intuition behind every way to solve the problem.

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

    Thank you Surya, was finally able to understand this.

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

    Amazing Explanation!

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

    Nice job @TECH DOSE

  • @b.sainathreddy4567
    @b.sainathreddy4567 4 роки тому +1

    Ur vedioes are just awesome

  • @AnjaliKumari-zm9zo
    @AnjaliKumari-zm9zo 5 років тому +2

    really nice video. but can you please upload a video for time complexity nlogn?

    • @techdose4u
      @techdose4u  5 років тому +1

      Yea sure :) Will take your advice in consideration as well.

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

    Can you please make a video on this problem with binary search and dp and O(nlogn) complexity with c++ code? Thank you :)

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

      I will make it later. Currently doing heap.

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

    Nice explanation!
    Could the condition be more restrictive?
    Sth like: arr[i] > arr[j] && lis[i] == lis[j]

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

    would have been great if you deduced this from the memoized solution of LIS

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

    from 14:00 to 14:20 is the main part

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

    sir, do you have any frequently asked interview questions list??

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

    the longest increasing subsequence can also be 5,8,7,9

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

      @@harshyadav5162 sorry I posted it when I hadn't learned abt it

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

      @@Pooh__7__peace ✌️

  • @shreyyy_marwaha
    @shreyyy_marwaha 3 роки тому +5

    Not very efficient algorithm. Its O(n^2).....can be done in nlogn. But still nice explanation 👍.

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

      👌🏼

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

      @@techdose4u can you please make a video on nlogn solution also?

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

      I will make it later. I am trying to cover the topics which are left.

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

      Just we need to search from 0 to i using binary search

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

    Please also upload video on binary search approach

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

    This can be done n*logn time with binary search. that's better with time complexity and easy to understand.

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

    Great 💯💯💯🙌🙌

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

    Hey can u please explain the method for calculating the subsequence itself more precise in a more general way. I guess we should start from the index max value of LIS array and traverse back for finding the index with 1less than the max value and along with that we even have to ensure that arr[i]

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

    can we reduce the time complexity to O(nlogn)?

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

      Yes it's possible.

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

      @@techdose4u can you make a video on that approach?

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

      @@techdose4usir, please make a video

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

      @@vaibhavkumar9192 I don't really know if people will get it :P But I will try it after completing the basic DSA series for placement :)

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

    there is no explanation for this algorithm in the description

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

    I am so weak in DP .. I attempted 15 questions and never able to think the DP approach by myself always have to look at the solution.

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

      Atleast try to understand from solutions or editorial. As long as you do it, you will be able to solve soon.

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

    Thanks! I understand !

  • @astitvasrivastav9484
    @astitvasrivastav9484 5 років тому +2

    is it bad if i m not able to think for the algo myself ?

    • @techdose4u
      @techdose4u  5 років тому +3

      I was not able to do it myself. People can't do without having any practice. You will need to practice. Practice more and your intuition for it will increase. It works with everyone. Someone catches faster and someone late, but the point is, everyone catches. So try harder :)

    • @astitvasrivastav9484
      @astitvasrivastav9484 5 років тому

      @@techdose4u thanks a lot and continue your work becoz i know your views are going to rise exponentially they are too good!!

  • @prateeksrivastava9
    @prateeksrivastava9 5 років тому +1

    Great Job!!!!Make More videos on DP.

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

    great video.

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

    Solution required with nLogn time complexity

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

    how does dp improve solution we can iterate from right to left use stack and push in stack if num is less than top of stack store size of stack in max ,run loop each time 1 less than previous to 0 .

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

    Thanks surya 😃😃

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

    what is the time complexity of that code ? is it o(nlog(n))?

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

    great explanation sir!

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

      Thanks for your motivation :)

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

    could you please do even 673. Number of Longest Increasing Subsequence problem ?

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

    Why can't we move from left to right to find the sub-sequence?

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

    pls do a video exclusive for basic code of backtracking

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

      I will do it in recursion series when I start it.

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

    The problem is I want to find greatest sum. So i must get and compare both the longest subsequence .

  • @PritamKumar-mr5dv
    @PritamKumar-mr5dv 3 роки тому +1

    great video.....

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

    is there any video of you eplaining lis in recursive manner though it is not optimal but recursion is important to do dp??

  • @Sweety-rx8zq
    @Sweety-rx8zq 3 роки тому

    can someone please explain that LIS comes under overlapping subproblems or optimal substructure?

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

    good explanation

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

    Sir can share the algorithm pls

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

    can you make a video on increasing decreasing and then increasing subsequence . fir e.x = a subsequence like ( 5 , 4, 19 )

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

    What will you do in element are repeated?

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

      We don't include Repeating elements in LIS.

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

    Why u use two for loops

  • @SaurabhSuman-wz1ex
    @SaurabhSuman-wz1ex 3 роки тому

    it should be done in nlogn time complexity

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

    Thanks again.....

  • @me-so2is
    @me-so2is 3 роки тому

    7:50 why lis[i]

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

    what do you mean by you will figure it out ? the main condition that need explaining you said you will figure it out. seems like you are just copying the code and saying it will work.

  • @1989ashok
    @1989ashok 5 років тому

    Which graphic tablet u r using to make this video ?

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

    why should we check lis[ i ]

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

    Thank you sir

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

    Dhanyawad

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

    its not giving correct output for printing lis

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

    You should have explained the second part of the if condition, just saying think about it doesnt equate to teaching.

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

    Aree sir phele backtarcking krana tha tabhi smj ata

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

    thanks bro

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

    Can anyone help me to store both the longest subsequences.

  • @soumalyadhar.28
    @soumalyadhar.28 3 роки тому

    if the array is 5 10 7 8 9 11 12 the LIS is 6 but the algorithm will give output of 4...the logic is not correct...