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...
Master Data Structures & Algorithms For FREE at AlgoMap.io!
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.
That's amazing! This one is pretty tricky for new programmers haha. I really appreciate it :)
I'm also interested in seeing a vid for the binary search approach!
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!
Excellent explanation!!! Thank you!
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.
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)
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.
Small update: I quickly implemented it and it works without issue in O(nlogn)
Thanks man ✌🏼
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
No I think it's pretty hard lol
@@GregHogg well not hard after your explanation lol
@@GregHogg Agreed. Coming up with a solution on your own is probably a nightmare.
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
Great video! Can you explain how to use binary search here?
What application do you use to write those notes?
leetcode
he draws with miro