Find The Longest Increasing Subsequence - Dynamic Programming Fundamentals

Поділитися
Вставка

КОМЕНТАРІ • 604

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

    Table of Contents: (yes, I know I'm screaming. I messed up...this video is old...ok.)
    Me Talking (Who Cares) 0:00 - 0:28
    The Problem Introduction 0:28 - 1:13
    LIS vs. LNDS vs. LDS 1:13 - 2:48
    The Approaches 2:48 - 4:38
    Full Dynamic Programming Table Walkthrough 4:38 - 16:45
    Applying This To Other Dynamic Programming Problems 16:45 - 17:18
    Time Complexity 17:18 - 18:00
    Space Complexity 18:00 - 18:13
    Handling Dynamic Programming In The Interview 18:13 - 18:43
    The Usual 18:43 - 19:01
    This problem also has an O( n * log(n) ) solution which is faster than the O( n ^ 2 ) DP solution here: leetcode.com/problems/longest-increasing-subsequence/discuss/74824/JavaPython-Binary-search-O(nlogn)-time-with-explanation
    In my opinion, this isn't practical to pull off in an interview if you have never seen this question before and that is what matters to me. So I covered the O( n ^ 2 ) way since it is more reasonable.
    The code for this question (with exhaustive comments for teaching purposes) is in the description. It is for the Longest Increasing Subsequence problem. We talked about the Longest Non-Decreasing Subsequence.

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

      can u tell from where i can learn dp. its too difficult to understand
      plz reply if u see this comment or make a video on this

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

      @@deepakpaliwal2200 He has a playlist for DP.

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

      Could you please sort the videos in DP playlist from easy to hard questions? It would be of great help!

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

      The book "Algorithm Design" by Kleinberg and Tardos is really good if you want a very deep understanding

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

      I wanted to but never ended up doing it :(

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

    the high spirit in your voice and the medium pace is really motivating and keeps our brain focused. thanks buddy for your favor.

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

      hahahaha, I'm just shouting...didn't have a mic

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

      @@BackToBackSWE was playing lofi in spotify and your loud voice sounded like its in syhnc with the beats

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

      Learning from him :p

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

      @@TejasM14 true

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

    "yes, we can" is very emotional. I will be very strong when I listen to this word. Feel that I can solve this algorithm question now! thanks, Ben

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

      hahahaha sure.

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

      You must be a fan of Barack Obama then lol

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

    Love how this dude always answers the why questions to the small things compared to other people on youtube

  • @theuiniqueps10
    @theuiniqueps10 4 роки тому +98

    Not all heroes wear capes, some wear glasses and a amazon tshirt too :D

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

    Dude, you nailed it straight home, perfectly. I had been struggling with this problem for most of my Saturday afternoon. After a gruesome day of zero-progress and infinite hopelessness, the sheer joy and sigh of relief of finally having understood another concept is what made the evening a little better. Thanks !

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

      haha nice, if you like this check out our coding interview class, I'm posting video like this frequently there

  • @debrc
    @debrc 4 роки тому +11

    The way you explained the problem is absolutely brilliant. Wasted my entire day on other videos.
    I'm following you for some months now, every video from you is absolutely Gold. More power to you!

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

    One of the most energetic guys I found explaining DP.
    Thank you.

  • @dcodernz
    @dcodernz 3 роки тому +7

    I like how consistent you go through the whole run of the algorithm. It really helps understand it.

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

    Finally someone could clearly explain (even to a non-native english speaker) this problem. I was beating my head against the wall because all explanations I've seen so far were difficult to understand, now I can easily understand the underlying code

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

    bro you are really a good teacher who tech something more essential rather than just the solution

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

    The more I watch your videos, the more I think that this channel deserves to grow.

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

      Hahahahaha, thanks and I know right? This isn't the most scalable content...I'm cooking up somethin'....just wait.

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

    Someone give this man a noble price...🙌❤

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

      haha thanks mate! subscribe to our DSA course with a flat 30% discount for some amazing content b2bswe.co/3HhvIlV

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

    Your videos are breaking certain things wide open for me that I've never seen before. Thanks man. I'm budgeting in time to watch at least one of your videos a night until I've seen them all

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

    I was looking at leetcode discussion solutions for an hour trying to wrap my head around and understand it, but after watching this video it completely clicked and could code the problem with ease!

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

    The amount of patience you have to explain this is commendable! Thanks!

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

    You did great. You did not mess up. You exhibited passion, which is very engaging to those in your audience. Great presentation.

  • @micmicmw
    @micmicmw 4 роки тому +12

    Honestly I like the loud voice you have. Wakes me up doing late night homework. Thank you tons can't wait to watch more videos.

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

    You are absolute mad-man by repeating those things. Thank you man, I can't believe you made me understund those things. Never stop!

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

    Every time I encounter a problem and don't understand it, I go to this channel.
    Huge thanks to you for explaining things so clearly, King.

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

    You are the best. There is no one on UA-cam who teaches fantastic as you

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

    Man, I went through 5 youtube videos and finally understand how to implement it from yours. You da best!

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

    You are better than 3/4th of the teachers I have studied from and one of the bests on online platforms! Keep going :)

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

    this is a 5 years old video, but i just wanted to say when it comes looking up problem my solutions, thanks to you i understood backtracking perfectly and now i watching this
    if i ever made transition into swe i am definitely crediting you

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

    I actually love that you're screaming. I can feel the passion. That's one things that makes your videos great. Please don't become dry and all "professional" with future videos or with the content on your website. That's too boring. You make the topics exciting and fun. That's contagious. Keep it up. And people, please go check out his leetcode-like website backtobackswe.com. It's awesome. So impressed you did this all while in college.

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

    Dude, the way you explain it (and your energy) really helps me absorb and understand this. Also the way you emphasize the key technique helps make it click.

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

    Only because of you i can understand dynamic Programming. Your one video explanation is sufficient to solve multiple other problems.

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

      Happy Holidays 🎉 Thank you for your kind words, Siddharth! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40

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

    Teaching is an art and you have mastered it . Oh captain , my captain . It is just pure joy learning from you.

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

    I wrote my code based on this method all by myself. Pretty proud of the baby steps. Thank you!

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

    Wow.
    THE BEST explanation of dynamic programming approach for this problem.
    Good teaching skills are rare and you've got them.
    Thanks for this!

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 5 років тому +1

    Best Ever Explanation.You are just putting all the lights in the way to darkness to achieve the Algorithmic Destination.Keep posting such videos.And really appreciate the kind of effort you are putting to make these informative videos.Thanks

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

    I rarely comment on videos, but I really appreciate your clear explanation. I was able to understand and code the solution based on your explanation by looking at your videos _just once_ - that's amazing!
    Keep up the good work! I'd love to donate/contribute to you once I pass my interviews at a Big N and get a job.

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

      thanks! and nah u good, just get the job

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

    Thanks for explaining the answers. I tried reading the explanations on blogs and leetcode, but they didn't click. Your videos already made things clicked for me and you teach the patten that I should recognize. DP is really hard for me for now, thanks for lessening the pain!

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

    One of the better explanations of the solution to this problem. Well done.

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

    This channel is one of the best about computer science

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

    After literally months of trying to figure out DP, after this video I finally got it!

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

    I struggled so much and your videos have really guided and helped me to clarity!

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

    first min in and was amazed by the way of explanation . Truly Respectable!

  • @DennisSmdFreefightTrainer
    @DennisSmdFreefightTrainer 4 роки тому +11

    I never find the 'code in the description'. In every single video I never find the code. Can you clarify where it is? Btw your are amazing and help me a lot, thanks!

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

      The repository is deprecated - we only maintain backtobackswe.com now

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

    The way you explain things is so easy to understand. Thanks for doing this.

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

    Thanks for the Amazon Falcon for posting video and save students' lives while working in Advengers.

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

    Thank you for being so clear, specific and for explaining everything slowly. You're way better than my teacher!

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

    You are a life saver! I cannot thank you enough for posting these!! Bless you!

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

    Your explanations are so intuitive and clear. I feel like I am starting to have a good feel on this subject after watching your videos. Love your awesome work!

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

    dude ur energy is superb that helps understanding better

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

    Thank you so much for this. This was of really great help and I must mention how the energy and positivity in your voice makes me really attentive.

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

    recently started interviewing, your videos are very helpful for solving leetcode problems in the most efficient way, i was even able to attempt hard category question on an actual interview after watching your videos, keep these videos coming \m/

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

      great

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

      @@BackToBackSWE can you please make a video about interleaving strings? The dynamic programming solution to the problem is a little difficult to understand and come up with.

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

      @@akankshajain3997 I can look into that but not sure I'll ever get to it

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

    I wish I watched this before my Amazon interview today. Although, they took it even further, and asked for longest geometric subsequence. Soul crushed...

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

      ur good - you'll make it

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

      Did you get your amazon shirt?

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

      Let's test you on random sh*t you'll never rarely come across in your day job, how about that?

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

    what an amazing way to build intuition for such problems! thank you!!

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

    The O(n log n) solution is niche but often in interviews they explicitly ask for an n log n solution. You have to follow a Binary Search approach to do that. Google Longest Increasing Subsequence Binary Search or Longest Increasing Subsequence nlogn for that.

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

    you are really a miracle teacher, thank you, professor.

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

    This is my first comment on youtube, but really dude you are seriously the best, loved your explanation... simple and clear, great job man keep it up :)

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

    At first, I was a little confused about what you meant by 'includes both bounds' for each of the sub-problems. Once I realized that you were only comparing the elements at i and j, it sort of clicked, but at the same time I realized there's a couple of flaws with the 'includes both bounds' requirement.
    - If the first element is the largest value in the array, then no non-decreasing subsequences including both bounds exist for any of the sub-problems.
    - All sub-problems after 0-0 should have a default answer of 2 instead of 1, since you're defining them to include both bounds.
    I think it makes more sense to say 'includes last element' instead.

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

    I could grab the solution straight away, very well explained, thanks!!

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

    Remember guys, when the problem says largest subsequence, it means the largest subsequence size. Both are slightly different things, hence why the shown approach may look a bit confusing at first.
    The intuition here is not that we are trying to find the largest subsequence size among all subsequences till a given element, no, instead we are trying to find all the subsequences including (or rather ending at) the given element while remembering which subsequence size was the largest, then doing it for the next element and so on. And finally, the largest subsequence size of an entire array is just the largest subsequence among all the largest subsequences. This is the reason why you may think that for an element at index i, the largest subsequence till it should simply be the largest of all subsequence sizes behind it, but with this approach, we are not trying to find the largest subsequence size till the element at index i, instead we are simply trying to find the largest subsequence that includes the element at index i and then storing the size of this subsequence.
    This could be bit confusing but once you understand it, you'll get why largest subsequence size and largest subsequence are slightly different and how you can subproblem it by looking at the question a little bit differently.

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

    I just have started learn DP. But after see your video, I now comprehend how it work. Thanks for awesome explainning 😎

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

    wow finally got it your explanation is crystal clearr....keep up the good energy!

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

    So much passion and enthusiasm in your style of explaining things. Thanks, man! Was really helpful.

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

    "Subproblem Subproblem Subproblem"
    Thanks Ben, now I'm feeling much more better about how to solve the DP questions
    By the way, I really like your T-shirt :)

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

    Much obliged but if you could take that drill sergeant tone down a notch next time, that would be even more fantastic .

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

    Love your lectures and love your energy, thanks so much for making these!

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

    Your videos are amazing, i love that you explain beyond just solving the problem. You're an amazing teacher

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

    Nice. Thank you for going through the entire thing, and cutting out the non-important clips.

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

    you and Abdul Bahri are carrying me through CS

  • @KishanPatel-fo8kh
    @KishanPatel-fo8kh 4 роки тому +1

    Hey I am new to programming I watch your videos to learn about such topics, I approached the problem in a bit different way what I did was made use of another temporary space and to store the given array in it but in sorted form. So now basically we can have two arrays(one given array and other sorted given array), we can find LCS (longest common sub sequence). I know the LCS is applied to strings but the idea here is pretty same. However your solution is anyways space efficient than mine.

  • @shafeenmahmud8850
    @shafeenmahmud8850 4 роки тому +4

    I love your energy and your videos
    For the dynamic programming videos like this one I think what you're missing is a section explaining what the core sub problem is, because that is the main challenge in dynamic programming, understanding the sub problem (which is not constant from problem to problem).

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

    You are like a missionary urging us to learn DP.

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

    Wonderful sir...ur explanation, is a concept building solution for many people.

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

    Thanks a lot, buddy you not only cleared the concept of this problem but also the core of DP. Appreciate your efforts :D

  • @DanDan-zs6wg
    @DanDan-zs6wg 5 років тому +2

    Great video! Thanks for taking the time to make this!

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

    thanks for the explanation of the algorithm....I got confused when i first saw the code, but watching the video, the idea behind it became clear :)

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

    Man, thanks God I have found your channel, this is so easy to understand now.

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

    Excellent explanation, better than mind numbing reccurrence relations.

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

    Now this is a great video, clear when speaking and dividing into very useful portions

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

      Really glad to help 🎉 Do you know about our 5-Day Free DSA Mini Course? Check it out here - backtobackswe.com/

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

    this guy shouted knowledge to my brain.and my brain accepted it.thank you bro

  • @zirkphoto
    @zirkphoto 8 місяців тому

    all your videos make the solution click, keep going!

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

    You are awesome dude ! I always felt DP was too complex but watching your vids have greatly simplified it !! Keep making more videos ! :)

  • @librae-5664
    @librae-5664 4 роки тому +1

    와씨ㅋㅋㅋㅋㅋㅋㅋㅋ 이거 한글자막 번역하고 싶너... 개좋다 진짜... 한국피플은 이런거 하시는분 어디 없남 ㅠㅠ 이래서 영어공부를 엸심히 해야된다니깐ㅋㅋㅋㅋㅋㅋ 개좋앙!! f*cking awesome bro!! thanks a lot

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

      Oh yeah we wanted to do subtitles but never got around to it. And thanks

  • @SR-we1vl
    @SR-we1vl 4 роки тому +1

    You put so much hard work to explain the concepts! You're the best!

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

      no u

    • @SR-we1vl
      @SR-we1vl 4 роки тому

      @@BackToBackSWE You always reply! Thanks! You should now remember my name!

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

    This was great, but sometimes I think it's best if you write down something like max (a, b) because it's easier to follow. Fewer mistakes would be nice too because then it leads to more brain power spent on trying to figure out where the mistake was. I see you wrote down min (....) with the coin change one and I feel like it was easier to understand. Keep up the great work tho! You're the best out here.

  • @The.Good.Gamer.Ps5
    @The.Good.Gamer.Ps5 3 роки тому

    I saw this problem as a graph problem and did a DFS. Sort of worked out for me. Still watching this video to get better insights though. Need help with the time complexity?

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

    After watching this video, it took me just 10 min to arrive at a solution for box stacking problem. **sentimental sobs**

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

    i wish you could teach me every one of my classes! great teacher greeat structure , great video overall !

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

    Your videos are awesome, you explain beyond just solving the problem. It's really good.

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

    Dude, you channel is growing quick. Now when I go to the discussion I'll first look for your user name bephrem.
    Thank you for all the helps!

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

      hahahahaha, I want it to grow faster. Too slow for me. Thanks.

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

    The best I have come across. Good work guys. Thank you for this

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

    Dude, just keep it up.. Awesome explaining
    I am absolutely sure that ur channel will explode

  • @623-x7b
    @623-x7b 2 роки тому

    Thank you for putting so much effort into your explanations

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

    You deserve more subscribers dude

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

    You are really amazing at explaining reasoning behind the solution. Thank you so much for your work.

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

    Love your energy brother!!

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

      Happy Halloween 🎃 Thank you, brother! You get some extraaa treats - 50% Off our exclusive lifetime membership use the code SPOOKY50 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=SPOOKY50

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

    Its a very good video, helped me a lot, thank you. I like it that u tackle every question with the way thinking should be done in order to get it during interviews. Its very helpful.

  • @NoorAli-uh4uq
    @NoorAli-uh4uq 4 роки тому +1

    Any Suggestions on how to be good at dynamic programming.? Thanks for the amazing content.

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

      You just have to do many problems and identify the patterns.

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

    Thank you so much for this video , I was stuck to solve this problem ,but after watching your video the problem seems easy now for me

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

      that's great to hear! There are other questions at - backtobackswe.com/ - Would love some feedback

  • @ShubhamKumar-rt8nb
    @ShubhamKumar-rt8nb 5 років тому +1

    i like the way you end the lecture
    and obivously your explanation.
    please make some more video on DP problems

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

    best way to make us understand. Keep going . Luv ur videos

  • @helloiam2mas
    @helloiam2mas 4 роки тому +4

    Dude you explanations are just so unbelievably good. Like seriously you should open a school or something haha.....also if you guys make T shirts or something, I'd buy one

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

    Thank you Benyam.. Like the previous videos, explained the concept really well...Thank you very much.

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

    Thank you so much for uploading this video.
    This helps me a lot, cuz I'm not good at dp.

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

    Well done! Quite a mouthful to handle at times, you did it well!