Longest Increasing Subsequence - Leetcode 300 - Dynamic Programming (Python)

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2025
  • Master Data Structures & Algorithms for FREE at AlgoMap.io/
    Code solutions in Python, Java, C++ and JS for this can be found at my GitHub repo here: github.com/gah...
    Complete DSA Pathway Zero to Hero: • Data Structures & Algo...
    Please check my playlists for free DSA problem solutions:
    • Fundamental DSA Theory
    • Array & String Questions
    • 2 Pointers Questions
    • Sliding Window Questions
    • Binary Search Questions
    • Stack Questions
    • Linked List Questions
    • Tree Questions
    • Heap Questions
    • Recursive Backtracking...
    • Graph Questions
    • Dynamic Programming (D...
    My Data Science & ML TH-cam Playlist: • Greg's Path to Become ...
    Learn Python and Data Science FASTER at mlnow.ai :)
    Support the content: / @greghogg
    Follow me on Instagram: / greghogg5
    Connect with me on LinkedIn: / greghogg
    Follow me on TikTok: / greghogg5
    Coursera Plus: imp.i384100.ne...
    My Favorite Courses:
    Data Structures & Algorithms:
    UCalifornia San Diego DSA: imp.i384100.ne...
    Stanford Algorithms: imp.i384100.ne...
    Python Data Structures: imp.i384100.ne...
    Meta Coding Interview Prep: imp.i384100.ne...
    Python:
    UMichigan Python for Everybody: imp.i384100.ne...
    Python Mastery from MLNOW.ai: mlnow.ai/cours...
    Google IT Automation w/ Python: imp.i384100.ne...
    Web Dev / Full Stack:
    Meta Front-End Developer: imp.i384100.ne...
    IBM Full Stack Developer: imp.i384100.ne...
    Meta Back-End Developer: imp.i384100.ne...
    John Hopkins HTML, CSS & JS: imp.i384100.ne...
    IBM DevOps: imp.i384100.ne...
    Cloud Development:
    AWS Fundamentals: imp.i384100.ne...
    GCP Cloud Engineer: imp.i384100.ne...
    Microsoft Azure Fundamentals: imp.i384100.ne...
    Game Development:
    Michigan State Unity Development: imp.i384100.ne...
    UColorado C++ for Unreal Engine: www.coursera.o...
    SQL & Data Science:
    SQL by MLNOW.ai: mlnow.ai/cours...
    Python for Data Science by MLNOW.ai: mlnow.ai/cours...
    Google Data Analytics: imp.i384100.ne...
    IBM Data Science: imp.i384100.ne...
    IBM Data Engineer: imp.i384100.ne...
    Machine Learning & AI:
    ML Mastery at MLNOW.ai: mlnow.ai/cours...
    ML w/ Andrew Ng: www.coursera.o...
    Deep Learning w/ Andrew Ng: imp.i384100.ne...

ความคิดเห็น • 20

  • @GregHogg
    @GregHogg  6 หลายเดือนก่อน +1

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @ibraheem_Zain
    @ibraheem_Zain 8 หลายเดือนก่อน +2

    You and your video are great as usual. I am new in the field of programming and your chanel is being one of my resources to how i should think as a programmer.
    Thanks for those great videos.

    • @GregHogg
      @GregHogg  8 หลายเดือนก่อน +3

      That's amazing! This one is pretty tricky for new programmers haha. I really appreciate it :)

  • @SemesterAtSeaHopeful
    @SemesterAtSeaHopeful 4 หลายเดือนก่อน +5

    I'm also interested in seeing a vid for the binary search approach!

  • @EquinoXReZ
    @EquinoXReZ 7 วันที่ผ่านมา

    Great explanation, I was able to come up with a solution after 2:54, with some struggling and a lot of print statements but got it eventually!

  • @julieirwin3288
    @julieirwin3288 5 หลายเดือนก่อน

    Excellent explanation!!! Thank you!

  • @notsaad
    @notsaad 5 หลายเดือนก่อน

    May be good to also go over the O(nlogn) binary search answer even if it is more difficult just to have the optimal solution presented.

    • @Erichteia
      @Erichteia 2 หลายเดือนก่อน

      The n log n is (I think) to realise that for each subarray length, you are only interested in the subarray that ends with the smallest number. E.g. if you have 2 subarrays of length 5 and 1 ends with a 6 and the other with a 9, the one with the 6 is the only one you want to keep, as it is more versatile.
      Once you know this, you only keep 1 subarray per possible length and you keep them sorted (shortest subarray to longest). Because you only keep subarrays that end with a larger number if their subarray longer than what you had before, a list that is sorted according to subarray length, will also be sorted according to the last number in the subarray. So you can do binary search on the list of possible subarrays, find the largest number smaller than your new number, and add the new number to it. This creates a new subarray that is 1 longer. This replaces the existing subarray you had that was 1 longer than the subarray you added an item to (as that subarray ended with a number higher than your current one)

    • @Erichteia
      @Erichteia 2 หลายเดือนก่อน

      So in short, either the new number N is larger than any number you’ve stored and you append a new subarray to the end of the list that is 1 longer than your longest one, the new number is smaller than you’ve ever seen and you replace the subarray of length 1, or it is in between and you find the first number smaller than N. Let’s say that’s the number on position L (with subarray length L+1). You add N to that subarray, making it one longer. Since N is smaller than the number on position L+1 (with a subarray of length L+2), you replace that number.

    • @Erichteia
      @Erichteia 2 หลายเดือนก่อน

      Small update: I quickly implemented it and it works without issue in O(nlogn)

  • @__RK__
    @__RK__ 7 หลายเดือนก่อน

    Thanks man ✌🏼

  • @Martinnnnnn-e5s
    @Martinnnnnn-e5s 6 หลายเดือนก่อน

    I spent so much time on this question, and everyone in the discussion section says this question is hard. But it's actually sooooo easy whattttttttt

    • @GregHogg
      @GregHogg  6 หลายเดือนก่อน +2

      No I think it's pretty hard lol

    • @Martinnnnnn-e5s
      @Martinnnnnn-e5s 6 หลายเดือนก่อน

      @@GregHogg well not hard after your explanation lol

    • @mohammadrafi895
      @mohammadrafi895 6 หลายเดือนก่อน

      ​@@GregHogg Agreed. Coming up with a solution on your own is probably a nightmare.

  • @abdulrahamanaslam5467
    @abdulrahamanaslam5467 8 หลายเดือนก่อน

    Hi Greg,I hope you are fine, I can't seem to understand how you developed all these thought processes and problem solving skills,I want to be like you ,I'm currently in my second year cs ,tell me something

  • @LawZist
    @LawZist 8 หลายเดือนก่อน +1

    Great video! Can you explain how to use binary search here?

  • @notsoeazy35
    @notsoeazy35 7 หลายเดือนก่อน

    What application do you use to write those notes?

    • @fantastic-b2m
      @fantastic-b2m 7 หลายเดือนก่อน

      leetcode

    • @vxel
      @vxel 2 หลายเดือนก่อน

      he draws with miro