Compute The Next Permutation of A Numeric Sequence - Case Analysis ("Next Permutation" on Leetcode)

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

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

  • @BackToBackSWE
    @BackToBackSWE  5 ปีที่แล้ว +29

    Table of Contents:
    The Problem Introduction 0:00 - 0:55
    The Approaches 0:55 - 1:58
    Investigation: How Are Permutations Built? 1:58 - 7:47
    Case Analysis: Deducing The Next Permutation 7:47 - 11:10
    Time Complexity 11:10 - 11:42
    Space Complexity 11:42 - 11:56
    Wrap Up 11:56 - 12:21
    The code for this problem is in the description. Fully commented for understanding and teaching purposes.

  • @Official-tk3nc
    @Official-tk3nc 4 ปีที่แล้ว +15

    Some Useless channels are getting 10 million subscribers but useful channels like these are still in their 100ks . THIS PROVES ONLY a FEW PEOPLE ARE SERIOUS

  • @avinandanbanerjee9568
    @avinandanbanerjee9568 4 ปีที่แล้ว +54

    I envy the intern you're going to mentor in a few years at Twitter. This was a brilliant and very lucid explanation!

  • @AlexTran
    @AlexTran 3 หลายเดือนก่อน +2

    This man is the most talented person I've ever watched on TH-cam.

  • @vedantiyangar151
    @vedantiyangar151 5 ปีที่แล้ว +12

    Every one of your videos gives me a light-bulb moment. I always say a loud "Ooooooooooooooooo" when I actually understand how things work. You're on another level, Ben.

  • @ivanluchev7996
    @ivanluchev7996 4 ปีที่แล้ว +1

    This is the best explanation one could give for permutations. The build-up makes it really easy to put the pieces of the algorithm together.

  • @janvisingla3746
    @janvisingla3746 4 ปีที่แล้ว +5

    Thank you for the great content :) . I spent like 3 hrs on this ques watching many videos and wasn't able to understand at all and suddenly land at your video and i was like "WOW HE IS SO GOOD" .Thank you again from INDIA :)

  • @shubhamchopra5518
    @shubhamchopra5518 5 ปีที่แล้ว +15

    You make a hard problem so easy to understand! Keep adding more content. Thanks, Benyam!

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว +2

      sure ha, I'm taking a bit of a break from this channel and run a private class now. But I have a cool video coming soon

  • @jy8887
    @jy8887 4 ปีที่แล้ว +3

    The best explanation I could find on the internet. I highly recommend this channel!

  • @symbol767
    @symbol767 2 ปีที่แล้ว +4

    You're doing Gods work bro, especially with that video breaking down finding the permutations, that was legendary. Thank you man!

    • @BackToBackSWE
      @BackToBackSWE  2 ปีที่แล้ว

      Thanks bud! try out some more amazing stuff in our 5 day free mini course backtobackswe.com/

  • @Hav0c1000
    @Hav0c1000 4 ปีที่แล้ว +1

    Really nice job! I read a couple articles about this problem, but none of them beat your walk through. This was great. I love how you walk through most algorithms without even having to touch a line of code... i honestly think that helps in absorbing the material...

  • @NoName-ef2gv
    @NoName-ef2gv 3 ปีที่แล้ว +1

    Crystal clear. You are one of the best teachers on youtube. Thank you.

  • @abhilashgoyal2234
    @abhilashgoyal2234 4 ปีที่แล้ว +1

    For those who are not getting this logic in one go, please refer to code first, try to think the logic, build a picture in your mind ( very high level) and then see this video. Perfect

  • @bahdjibrildjibril
    @bahdjibrildjibril 5 ปีที่แล้ว +2

    This is for sure my new go to resource. I love the clarity and the fact that you take the time to explain very well in details. I just feel like you explain this just like I need. Thanks so much again for the efforts.

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      thanks! check this out late July twitter.com/thebigoguide, it is the next leg of this project

  • @shubham_sinha1
    @shubham_sinha1 4 ปีที่แล้ว +6

    My goodness .....what an amazing explanation !!! U make any problem so so easy ......I saw ur explanation video on kadane's algorithm and subscribed immediately!!!

  • @Kgp-ty5dk
    @Kgp-ty5dk 5 ปีที่แล้ว +2

    fantastic explanation! I implemented this two years ago. revised everything in 10 minutes and implemented again!

  • @watchClips661
    @watchClips661 3 ปีที่แล้ว +1

    That's a brilliant way to approach the problem. Thanks!

  • @clashingwithsahib
    @clashingwithsahib 3 ปีที่แล้ว

    Your 30 minutes of back to back recursion backtracking and this video made my concept of next permutation crystal clear thanks.

  • @mithunk9210
    @mithunk9210 5 ปีที่แล้ว +1

    Your videos are a saviour to me! I bet most courses can't match the passion and dedication you put into these videos! Hats off!!
    Thank you so much for giving me hope that I can solve all the questions with the right thought-process and practice. I have been recommending your videos to all my friends who are struggling with interviews. Thanks again!!!

  • @alexpena9927
    @alexpena9927 4 ปีที่แล้ว +7

    i came here for leetcode help, now I am rethinking my entire life because I did not notice the 3

  • @AE-ql7vo
    @AE-ql7vo 4 ปีที่แล้ว +2

    Dude! You’re really talented in simplifying tough concepts. Thanks a lot!

  • @rohan8arora
    @rohan8arora 5 ปีที่แล้ว +1

    nobody explained it like you did. Kudos!

  • @DiaryOfMuhib
    @DiaryOfMuhib 5 ปีที่แล้ว +1

    The only video where I got an in-depth explanation. Thanks a lot.

  • @prachurjyabasistha4682
    @prachurjyabasistha4682 4 ปีที่แล้ว +5

    This is the best explanantion for this problem!!

  • @tumble_dont_fall
    @tumble_dont_fall 4 ปีที่แล้ว +1

    man. you're actually blessed with knowing how to explain. this is like...really, really awesome explanation. nice work!

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว

      I'm normal. and thanks and thanks

  • @akashmittal5638
    @akashmittal5638 ปีที่แล้ว

    This is the best possible explanation there can exist on this problem. I've seen lots of your amazing videos before, but this one is by far the best. I don't think I can ever forget this simple logic, thank you Ben!

    • @BackToBackSWE
      @BackToBackSWE  ปีที่แล้ว

      Thank you, appreciate it 😄 Also check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉

  • @ishan7824
    @ishan7824 2 ปีที่แล้ว

    Finally someone who hasn't crammed the algorithm. Thank you for this gem :)

    • @BackToBackSWE
      @BackToBackSWE  2 ปีที่แล้ว

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

  • @snlagr
    @snlagr 4 ปีที่แล้ว +2

    i like the yellowish color tint of this video. Kind of soothing to watch.

  • @abhishekthakur6612
    @abhishekthakur6612 5 ปีที่แล้ว +3

    The way you explain is just awesome. The clarity in explanation and presentation , the way you emphasize on an algorithm is just too elaborative. Thanks. Love from INDIA ❤❤

  • @animatedzombie64
    @animatedzombie64 3 ปีที่แล้ว

    best ever explanation for this problem on the youtube.

  • @narihanellaithy7726
    @narihanellaithy7726 5 ปีที่แล้ว +4

    I loooooove you! I was about to lose my mind! saw this problem in EPI and I was like wtf! Thank you :')

  • @hritiksaroj3147
    @hritiksaroj3147 4 ปีที่แล้ว +11

    Would love to see some design questions on your channel!!!Btw Awesome explanation!!

  • @李泽鑫-c1v
    @李泽鑫-c1v 5 ปีที่แล้ว +1

    This should be one of the best explanation people can see. Your videos should deserve way more views. But keep going, I believe that there will be way more people subscribing your channel.

  • @prakharsingh620
    @prakharsingh620 2 ปีที่แล้ว +1

    What an explanation man
    Great work

  • @resetengineering
    @resetengineering 2 ปีที่แล้ว

    This is hands down the best explanation. Watched a couple of videos which even claim to explain intuition, but they don't really. There were micro points in my mind that were cleared at each point of the video. Hooked me on to get through it with patience. Else I switch due to BS

  • @ShivamShukla-uz9xs
    @ShivamShukla-uz9xs 4 ปีที่แล้ว +1

    Thanks a lot for such a beautiful and intuitive explanation from the scratch and origin of the problem. How you drove the case analysis to the conclusion to solve the problem was really the awesome part. Thanks that helped a lot.

  • @vanshikabajaj4323
    @vanshikabajaj4323 3 ปีที่แล้ว

    literally amazing! i have gone through a lot of videos but the way you explained is amazing dude.

  • @zionhuang5993
    @zionhuang5993 5 ปีที่แล้ว +6

    DUDE! Your explanation is best I have ever seen! Your thought about the process of permutation really help me. You have real talent.

  • @szarusz
    @szarusz 4 ปีที่แล้ว +1

    A fantastic explanation. I knew this problem, I knew the solution, but I never understood it as deeply as I do right now.

  • @amishagupta2694
    @amishagupta2694 5 ปีที่แล้ว +1

    Literally my first comment on You Tube. Your explanation is one of the best I have seen online

  • @mayanksharma-qv4qm
    @mayanksharma-qv4qm 5 ปีที่แล้ว +2

    dude you are amazing, you deserve a lot more subscriptions!

  • @alokuttamshukla
    @alokuttamshukla 4 ปีที่แล้ว +1

    Holy moly !!! what an explanation you have put.

  • @mystryb345
    @mystryb345 4 ปีที่แล้ว +1

    Bro your Are GOAT

  • @dochaar
    @dochaar 4 ปีที่แล้ว +2

    Benyam, thank you so much for your efforts. You have explained things in a way most people can't! There is a huge difference in knowing things and teaching them in a way to make others understand. You have certainly mastered that art. I once watched a video on youtube about linked lists by Dave Feinberg almost 8 years ago and till date it's imprinted in my memory. And, I pretty much solved any linked in question after that. Your explanation is definitely as good as it! I have a seen a few other videos made by you, especially the one on bit shifting (adding two numbers without using add operand). I became your fan after that! Thank you so much sir! Keep doing what you do the best :)

  • @harimlee2172
    @harimlee2172 4 ปีที่แล้ว +3

    My first comment on TH-cam -- this is such a great explanation thank you so much!

  • @manasbohat6883
    @manasbohat6883 4 ปีที่แล้ว

    Best video on this problem on the internet

  • @manokumar89
    @manokumar89 3 ปีที่แล้ว

    Amazing explanation. Concentrating on the intuition on how to come up with that algorithm and why this algo works rather than stating that this is the algo, this is the code and this is how the code works (which is what is explained almost everywhere). Thank you so much. Gonna see all the videos in your page _/\_ Best 12 minutes spent on youtube.

  • @yunlongsong4521
    @yunlongsong4521 5 ปีที่แล้ว +1

    Great video. The algorithm is easy to remember, but not understanding it completely could cause negative effect in an interview. Thank you for your intelligible explanation!

  • @gautamkumarshukla3055
    @gautamkumarshukla3055 3 ปีที่แล้ว

    Very good explanation , as it not only explains how to do it, but also tells underlying pattern for why to do it this way

  • @linarudashevski166
    @linarudashevski166 5 ปีที่แล้ว +1

    what is the link to the permutation video referenced around 1:52?

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      Should be somewhere in the channel videos

  • @jinliu5928
    @jinliu5928 5 ปีที่แล้ว +1

    Great explanation on decreasing order is the last state of permutation!

  • @minicraft9158
    @minicraft9158 3 ปีที่แล้ว

    if i have to define this video in one word.. i would say...'brilliant'

  • @nelsonthekinger
    @nelsonthekinger 4 ปีที่แล้ว +1

    Impressive explanation! A "Real Intellectual Jump"! I was bubble sorting the right side for no use!
    Thank you very much, this is star quality material!

  • @thinja
    @thinja 3 ปีที่แล้ว

    Amazing. I thought I would never understand this from first principles, but you did it!

  • @armaanpathan1856
    @armaanpathan1856 3 ปีที่แล้ว

    Whenever I need to understand the logic of how things work in complex programs
    Step 1 youtube
    Step 2 Search Back to Back SWE
    ... and I live happily forever after 😂
    Thank you for this great explanation ❤

  • @nickk5050
    @nickk5050 2 ปีที่แล้ว

    wow great explanation, I figured it out along the way w/ ur leading discussion

  • @anonymousvine4105
    @anonymousvine4105 3 ปีที่แล้ว

    A slightly more intuitive way to think of it is that you’re given an integer, then your task is to find the very next integer greater than this one by only using the digits given. You want to consider the set of unused digits from right to left. For example 45321. Check the tens place, is 1 > 2? No. Okay, we’ve exhausted our unused digits, add 1 to the unused set, then backtrack to the hundreds place. Are 1 or 2 > 3? No. Add 3 to the decision space and move on to the thousands place. Continue with 5. Are 1, 2 or 3 > 5? No, so add 5 to the unused set and backtrack to the ten-thousands place. Is 5 > 4? Yes, so now we want to construct the smallest integer we can that starts with 5 and must use 1, 2, 3, 4.
    Stepping back, we see that 45321 would indeed come before 51234 if these were the only digits we could use to construct integers. The algorithm is more natural to think of if we go back to our grade school intuition of how to construct bigger numbers.

  • @amitranjan6998
    @amitranjan6998 5 ปีที่แล้ว +1

    Hi , i am little bit confused in the example i.e 7:52 minutes , can't understand what you means by putting 6 to the space ,it's going out of space , then 2 , why ?

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      6 is already planted (at index 0), 2 is already planted (at index 1), 1 is already planted (at index 2). These tell us what numbers we have left to work with to populate going forward in our recursion. Does this make sense?

    • @amitranjan6998
      @amitranjan6998 5 ปีที่แล้ว +1

      @@BackToBackSWE Thanks got it , i really likes your video .Thanks alot , if you can make more video on the dynamic programming and backtracking ,kindly do so . Your effort is really helpful to others .

  • @MithleshKumar-iz1dz
    @MithleshKumar-iz1dz 5 ปีที่แล้ว +1

    Great and simple. Thanks BTB SWE team!

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      Hahaha it is just me now, but I'm working with others shortly.

  • @vaibhavkumar4821
    @vaibhavkumar4821 5 ปีที่แล้ว +1

    Thanks and kudos for the on-point in-depth explanation for not so simple problem. Do you have any other recommended problems for exercise that revolve around the core idea explained in this problem?

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว +1

      generating permutations (the problem) is a good followup

    • @vaibhavkumar4821
      @vaibhavkumar4821 5 ปีที่แล้ว +1

      @@BackToBackSWE Thanks :)

  • @neelmanivispute1122
    @neelmanivispute1122 5 ปีที่แล้ว +2

    Thank you so much for helping out beginners like me. :) . Keep it up.

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      Sure, you will not be a beginner forever. Remember that.

  • @4sky
    @4sky 5 ปีที่แล้ว +3

    So algo is..
    1) find the decreasing section at the end of the array
    2) the item before the decreasing section swap with the next biggest number in the decreasing section.
    3) reverse the decreasing section.

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว

      yes, but make sure u know why, the pattern is simple, the why is deeper

  • @harshg7262
    @harshg7262 3 ปีที่แล้ว

    Incredible explanation, I have no clue how any company excepts someone to figure this out in 45 minutes tho

  • @Adam-tz6gk
    @Adam-tz6gk 2 หลายเดือนก่อน

    Beautiful explanation right here folks

  • @kshitij3394
    @kshitij3394 14 วันที่ผ่านมา

    Bro really loved your way of explanation. Kudos 👏

  • @abdaa5579
    @abdaa5579 4 ปีที่แล้ว +1

    Thanks for explanation. You are a good teacher.

  • @kartikdutta5410
    @kartikdutta5410 4 ปีที่แล้ว +1

    Amazing works. Hats off to your detailed explanation

  • @मयंकपठानियाँ
    @मयंकपठानियाँ 3 ปีที่แล้ว

    thanks
    I didn't even understood "lexicographical permutation" from problem but you explained it well.

  • @ec5988
    @ec5988 3 ปีที่แล้ว

    Takes a legend for me to leave a comment and you sir, are a legend

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

    Thanks a lot!
    Greetings from Brazil!

  • @rajparekh08
    @rajparekh08 3 ปีที่แล้ว +1

    very very well explained.

  • @konfukuzawa
    @konfukuzawa 5 ปีที่แล้ว +1

    Such a clear explanation, thanks buddy!

  • @deepakprajapati2635
    @deepakprajapati2635 4 ปีที่แล้ว

    great explanation, I hate those videos in which they first write code and show how their code works.
    I like the kind of videos made by you

  • @adityadhanrajtiwari
    @adityadhanrajtiwari 4 ปีที่แล้ว +3

    You are amazing bro ,you make programming interesting.
    ☺️

  • @atulmalakar
    @atulmalakar 5 ปีที่แล้ว +4

    I am in love with your explanation! ❤

  • @SmokyBigSmoke
    @SmokyBigSmoke 4 ปีที่แล้ว +1

    Can't thank you enough.This explanation was so good.

  • @syedsafdarali4287
    @syedsafdarali4287 4 ปีที่แล้ว +1

    Smooth explanation LOVED IT!

  • @AdityaGuptaYouTube
    @AdityaGuptaYouTube 5 ปีที่แล้ว +1

    This video is just mind-blowing. One of the most elegant solutions!! I watched some of your videos and tried my best to solve them by myself, but the approach of this question is just very very good. Keep up the good work buddy, and keep posting videos like this. :)

  • @siyiyu1916
    @siyiyu1916 3 ปีที่แล้ว

    Really like your video! Especially helpful for leetcode beginner like me!

  • @greentealatte2845
    @greentealatte2845 4 ปีที่แล้ว +1

    thank you!!!

  • @gyanasahu1006
    @gyanasahu1006 4 ปีที่แล้ว +1

    Very nicely explained indeed!!

  • @no5xx
    @no5xx 5 ปีที่แล้ว +2

    Awesome explanation dude. Would love to support your cause !!! xD

  • @harshitpandey638
    @harshitpandey638 5 ปีที่แล้ว +1

    Really amazing video , im blown away .

  • @umapathybabu8397
    @umapathybabu8397 4 ปีที่แล้ว +1

    excellent video, made to understand the problem clearly. looking more from you. can you do some oo design questions?

  • @fanchelsea844
    @fanchelsea844 4 ปีที่แล้ว +1

    thank you for your videos, they are great and easy to understand. Saludos desde México.

  • @ChrisKSP
    @ChrisKSP 2 วันที่ผ่านมา

    Dang that was a great explanation and you didn't even need to tell us any code.

  • @MuhammadIrshadAli
    @MuhammadIrshadAli 4 ปีที่แล้ว +2

    Thank you for making such a great video.

  • @tenki_desu
    @tenki_desu 4 ปีที่แล้ว +3

    牛逼啊
    English Translation: This is freaking AWESOME
    And this is the BEST explanation I have ever heard for the next permutation problem.

  • @geesehoward8838
    @geesehoward8838 4 ปีที่แล้ว +1

    great video and great explanation!

  • @JacobAbraham-twozerosix
    @JacobAbraham-twozerosix 5 ปีที่แล้ว +2

    Thank you! For this... I struggled with this quite a bit... Just could not see the pattern.

  • @rohitsanjay1
    @rohitsanjay1 4 ปีที่แล้ว +1

    You're a legend

  • @liangtang2127
    @liangtang2127 5 ปีที่แล้ว +1

    amazing explanation! it really helps me understand what leetcode 32 wants me to do :)

  • @prodigysonhiddenforareason1239
    @prodigysonhiddenforareason1239 3 ปีที่แล้ว

    Clear as thin air.

  • @dontknow7333
    @dontknow7333 4 ปีที่แล้ว +1

    thanks a lot

  • @valkon_
    @valkon_ 2 ปีที่แล้ว

    Thanks for the amazing explanation.
    The interviewers really have the audacity to ask if we seen this question before. Of course we have.

    • @BackToBackSWE
      @BackToBackSWE  2 ปีที่แล้ว

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

  • @ramprasadrai4101
    @ramprasadrai4101 3 ปีที่แล้ว

    Awesome clarity, love it !

  • @Prashantkumar-pn6qq
    @Prashantkumar-pn6qq 4 ปีที่แล้ว

    Amazing explanation fella. Appreciate that!

  • @renon3359
    @renon3359 4 ปีที่แล้ว

    Dude, you are awesome. brilliant explanantion.

  • @aashimaa2681
    @aashimaa2681 2 ปีที่แล้ว

    best explanation for this problem!

  • @CCC-lp5yc
    @CCC-lp5yc 4 ปีที่แล้ว +1

    Good explanation! Thank you!