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.
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
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.
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 :)
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...
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
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.
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!!!
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!!!
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!
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 ❤❤
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.
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
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.
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 :)
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.
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!
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!
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 ❤
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.
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 ?
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?
@@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 .
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?
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.
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. :)
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.
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
lol nah it makes sense
Knowledge never sells.
I envy the intern you're going to mentor in a few years at Twitter. This was a brilliant and very lucid explanation!
thanks heh
This man is the most talented person I've ever watched on TH-cam.
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.
hahaha nice
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.
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 :)
sure from AMERICA
You make a hard problem so easy to understand! Keep adding more content. Thanks, Benyam!
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
The best explanation I could find on the internet. I highly recommend this channel!
thanks
You're doing Gods work bro, especially with that video breaking down finding the permutations, that was legendary. Thank you man!
Thanks bud! try out some more amazing stuff in our 5 day free mini course backtobackswe.com/
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...
nice
Crystal clear. You are one of the best teachers on youtube. Thank you.
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
ye
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.
thanks! check this out late July twitter.com/thebigoguide, it is the next leg of this project
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!!!
great to hear
fantastic explanation! I implemented this two years ago. revised everything in 10 minutes and implemented again!
nice!
That's a brilliant way to approach the problem. Thanks!
Your 30 minutes of back to back recursion backtracking and this video made my concept of next permutation crystal clear thanks.
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!!!
haha thanks
i came here for leetcode help, now I am rethinking my entire life because I did not notice the 3
ye
Dude! You’re really talented in simplifying tough concepts. Thanks a lot!
sure!
nobody explained it like you did. Kudos!
thanks
The only video where I got an in-depth explanation. Thanks a lot.
ye
This is the best explanantion for this problem!!
thanks
man. you're actually blessed with knowing how to explain. this is like...really, really awesome explanation. nice work!
I'm normal. and thanks and thanks
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!
Thank you, appreciate it 😄 Also check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉
Finally someone who hasn't crammed the algorithm. Thank you for this gem :)
Thank you, glad you liked it 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
i like the yellowish color tint of this video. Kind of soothing to watch.
lol - it was a mistake
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 ❤❤
thanks :)
best ever explanation for this problem on the youtube.
I loooooove you! I was about to lose my mind! saw this problem in EPI and I was like wtf! Thank you :')
nice
Would love to see some design questions on your channel!!!Btw Awesome explanation!!
will do
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.
thanks
What an explanation man
Great work
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
thank you so much!
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.
Sure.
literally amazing! i have gone through a lot of videos but the way you explained is amazing dude.
DUDE! Your explanation is best I have ever seen! Your thought about the process of permutation really help me. You have real talent.
sure
A fantastic explanation. I knew this problem, I knew the solution, but I never understood it as deeply as I do right now.
great
Literally my first comment on You Tube. Your explanation is one of the best I have seen online
ay nice, welcome
dude you are amazing, you deserve a lot more subscriptions!
thanks
Holy moly !!! what an explanation you have put.
thanks
Bro your Are GOAT
thanks
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 :)
much thanks, all the best
My first comment on TH-cam -- this is such a great explanation thank you so much!
great and thanks and sure
Best video on this problem on the internet
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.
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!
sure
Very good explanation , as it not only explains how to do it, but also tells underlying pattern for why to do it this way
what is the link to the permutation video referenced around 1:52?
Should be somewhere in the channel videos
Great explanation on decreasing order is the last state of permutation!
thanks
if i have to define this video in one word.. i would say...'brilliant'
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!
sure
Amazing. I thought I would never understand this from first principles, but you did it!
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 ❤
wow great explanation, I figured it out along the way w/ ur leading discussion
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.
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 ?
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?
@@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 .
Great and simple. Thanks BTB SWE team!
Hahaha it is just me now, but I'm working with others shortly.
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?
generating permutations (the problem) is a good followup
@@BackToBackSWE Thanks :)
Thank you so much for helping out beginners like me. :) . Keep it up.
Sure, you will not be a beginner forever. Remember that.
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.
yes, but make sure u know why, the pattern is simple, the why is deeper
Incredible explanation, I have no clue how any company excepts someone to figure this out in 45 minutes tho
Beautiful explanation right here folks
Bro really loved your way of explanation. Kudos 👏
Thanks for explanation. You are a good teacher.
thx
Amazing works. Hats off to your detailed explanation
thx
thanks
I didn't even understood "lexicographical permutation" from problem but you explained it well.
Takes a legend for me to leave a comment and you sir, are a legend
Thanks a lot!
Greetings from Brazil!
very very well explained.
Such a clear explanation, thanks buddy!
sure
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
You are amazing bro ,you make programming interesting.
☺️
ye
I am in love with your explanation! ❤
thanks
Can't thank you enough.This explanation was so good.
sure!!
Smooth explanation LOVED IT!
thanks
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. :)
yessir
Really like your video! Especially helpful for leetcode beginner like me!
thank you!!!
sure!
Very nicely explained indeed!!
thx
Awesome explanation dude. Would love to support your cause !!! xD
yo
Really amazing video , im blown away .
ye
excellent video, made to understand the problem clearly. looking more from you. can you do some oo design questions?
sure
thank you for your videos, they are great and easy to understand. Saludos desde México.
wassup!
Dang that was a great explanation and you didn't even need to tell us any code.
Thank you for making such a great video.
sure
牛逼啊
English Translation: This is freaking AWESOME
And this is the BEST explanation I have ever heard for the next permutation problem.
thanks lol
great video and great explanation!
thanks!
Thank you! For this... I struggled with this quite a bit... Just could not see the pattern.
sure
You're a legend
no im normal
amazing explanation! it really helps me understand what leetcode 32 wants me to do :)
nice
i guess it's 31
Clear as thin air.
thanks a lot
sure
Thanks for the amazing explanation.
The interviewers really have the audacity to ask if we seen this question before. Of course we have.
Thank you, glad you liked it 😀
Do check out backtobackswe.com/platform/content
and please recommend us to your family and friends 😀
Awesome clarity, love it !
Awesome, thank you!
Amazing explanation fella. Appreciate that!
sure
Dude, you are awesome. brilliant explanantion.
best explanation for this problem!
Good explanation! Thank you!
sure!