@@behindthescene4406 if he will not iterate from second last then (i+1) will give array out of bound for (i= a.length-1).. that's why since we are comparing i with i+1.. we are starting from a.length-2
instead of swapping first, we can reverse first, then to find the first greater element we can use upper bound. Time complexity will be O(n + logn) = O(n) only but runtime will be fast.
@@takeUforward sir, u said there will be inc and then dec sequence,but if it was asked find next perm of 213,there isn't incre/dec it's dec and inc ,how to find break point.
after understanding the problem and the great explanation by striver also it tooks me 5-6 hourse literally if anyone wants the python code u can refer class Solution: def nextPermutation(self, N, arr): n = len(arr) if n = 0 and arr[i] >= arr[i+1]: i -= 1 # ... if i < 0: # It shows that all the elements are in descending order. arr[:] = arr[::-1] #for reversing the array return arr else: # 2nd Step... j = n-1 while arr[j]
Please watch the new video which covers it in more depth, and also prints it: ua-cam.com/video/JDOXKqF60RQ/v-deo.html Better Explanation here: ua-cam.com/video/JDOXKqF60RQ/v-deo.html&lc=UgwUFtp9qorT4WtGZUR4AaABAg This video's explanation tends to fail for some, so prefer watching the above lecture.
Understood. Great job. Can you please provide Problem Links for every problem in SDE sheet, it is sometimes difficult to figure out the problem you are intending that should be solved by us. Thank you
hey, @striver I request you to please use simple vocabulary for students like me. I had to watch your videos multiple times and couldn't understand them at once.
@@behindthescene4406 Because the last index will be in increasing order. Break point can be at second last index or third last index or fourth last index and so on.....
Such amazing explaination. I had read articles and thought that this is a very difficult problem. But this intuition and the explanation made easy. Thank you so much!!!!!
watched many videos of yours, but now before watching any new videos I priorly hit like!! :) bcz this channel had won my emotions in coding. great going thanks man!!
What if there are duplicates which are greater than your pivot.? Which one will you choose? starting one or last one? and why? Consider this case: [2,3,1,3,3] answer will come by choosing the right one.. but why?
so if array is 1,2,4,3,5 id1=1 traversing from right id2=4 swapping 1,5,4,3,2 reversing from id1+1 =>1,5,2,3,4 which is wrong o/p->1,2,4,5,3 . . . . traversing from right find the breaking point say id1 find next greater element from id1+1 to len(arr)-1 say id2 swap id1,id2 reverse from id1+1 to len(arr)-1
Thank you striver ❤️ got placed at paytm and this was the first question asked in interview 😍😍
dude really?
Brother inform us other questions as well through comments.....that would be helpful for us.....
Gib Referral
@@MrKingchamp1000 seppling rong viro
@Suryansh did they ask intuition behind this problem.
Just a suggestion, algo is quite easy but watch this video 2 or 3 times to get a clear picture of the intuition.
Keep it up, brother.....!!!
Only this guy can clear my doubt, I always search a problem and I’m feel blessing when he was already made video on that algorithm
Trust me
You won't get a better explanation than this one.🔥
bro can u plz tell me y he said break point is the second last at 10:15
@@behindthescene4406 the breapoint can be at 2nd last index in best case. hence it is better to iterate from that index
@@behindthescene4406 if he will not iterate from second last then (i+1) will give array out of bound for (i= a.length-1).. that's why since we are comparing i with i+1.. we are starting from a.length-2
check out back to back swe channel
instead of swapping first, we can reverse first, then to find the first greater element we can use upper bound. Time complexity will be O(n + logn) = O(n) only but runtime will be fast.
THIS IS ONE OF THE MOST UNDERRATED CHANNEL IN THE ASPECT OF CONTENT ..... DUDE YOU ARE ACTUALLY MAKING OUR FUTURE SECURE !! THANKS A LOT !!!
My potato brain did not understand this even after watching the video twice
even my potato brain cannot understand this bro , what to do 😂
Never thought of these type of intuition,absolutely brilliant.
I was stuck doing this question for many days but now u cleared my doubts .
Thanks for your effort
Glad to hear that
Thumbnails are becoming great day by day...
Yeah its very attractive
He hired someone to create for him.. Anyway it's good
Simply brilliant..
I have not seen anyone explaining this beautifully.
Thanks!! Cheers!!
@@takeUforward sir, u said there will be inc and then dec sequence,but if it was asked find next perm of 213,there isn't incre/dec it's dec and inc ,how to find break point.
@@sairam3351 reverse it bro
after understanding the problem and the great explanation by striver
also it tooks me 5-6 hourse literally
if anyone wants the python code u can refer
class Solution:
def nextPermutation(self, N, arr):
n = len(arr)
if n = 0 and arr[i] >= arr[i+1]:
i -= 1
# ...
if i < 0:
# It shows that all the elements are in descending order.
arr[:] = arr[::-1] #for reversing the array
return arr
else:
# 2nd Step...
j = n-1
while arr[j]
Small error at line 8 java code u have to put j>i along with & . Try this [1,3,1]
The explanation of the intuition just blew me, wow man, just wow.🔥
bro, Would you mind explaining what you mean by intuition when it comes to coding problems?
striver, you are saving lives man!!
Wow!!! Mind blowing explanation! That too in nearly 10 min! I love this series :)
literally best video for next permutation, thanks
I was watching this and thinking "there's no way there's any intuition to this" and was completely blown away by last..hats off
In C++ Code ,if your Output is not matching just replace nums.begin()+k+1 in the end to nums.begin()+k. only it will give correct output.
Please watch the new video which covers it in more depth, and also prints it: ua-cam.com/video/JDOXKqF60RQ/v-deo.html
Better Explanation here: ua-cam.com/video/JDOXKqF60RQ/v-deo.html&lc=UgwUFtp9qorT4WtGZUR4AaABAg
This video's explanation tends to fail for some, so prefer watching the above lecture.
Understood !!
Narayana Pandita's Algorithm...😊😊😊
Understood bro! Thank you 😀
Understood!
Thank you :)
Understood. Great job.
Can you please provide Problem Links for every problem in SDE sheet, it is sometimes difficult to figure out the problem you are intending that should be solved by us. Thank you
super explanation in the UA-cam ever searched
One of the best explanations for this question on youtube......Thanks!!!!!
Glad you think so!
Looks like first video without any dislike and 1k+ views🤩🤩
hehe
After watching the video 4 times. Finally understood the intuition
really explanation of intution behind algorithm force was the best thing ever.
You explains every problem in the best way...
Thanks!! Cheers!!
This is good video that explains the problem well. It's obvious starting from 4:50. Thank you
Really respect for you has gone to the next level, Super brilliant explanation 🔥✔️👌
bro can u plz tell me y he said break point is the second last at 10:15
I knew the algorithms for this problem but finally I know intuition also, after watching this video.
Definitely, better than other videos...
hey, @striver I request you to please use simple vocabulary for students like me. I had to watch your videos multiple times and couldn't understand them at once.
The way you explain, even the hard problem seems easy, so i am subscribing you. Thank you
Thank you very much, understood 🙂✌️
Striver why u explained so well? Thank God you love coding. Now, helping many.
Amazing Intuition and Algorithm
please explain why at 2:36 even the element at 0th position also satisfies the condition of a[i]
I think it should be a[i]>a[i+1]; the reason behind this is that we are traversing from backward.
This is such a great explanation for such an opaque algorithm. Thank you!
we can also use the binary search to reduce searching overhead.
Thank u bhaiya thanks to tell intuition of this algorithm 👩💻😍😍😍
Anyone suggest please. Even after able to solve the question should I watch these videos ?? as I have heard He explain very nicely
Hats Off Man! Never have I ever seen this classic problem being explained in such a manner. especially the intuition! Thanks Man!
Glad it helped
Lol, finally I was able to get an approach similar to Striver sir. I came here to learn newer approach. This gives me confidence.
Beautiful explanation and to the point. Thanks a lot!
bro can u plz tell me y he said break point is the second last at 10:15
@@behindthescene4406 Because the last index will be in increasing order. Break point can be at second last index or third last index or fourth last index and so on.....
You are awersome. good job.
Such amazing explaination. I had read articles and thought that this is a very difficult problem. But this intuition and the explanation made easy. Thank you so much!!!!!
Every time I visit your videos I got some nice learning Thank you striver🔥👌
Happy to hear that!
U are doing great work Sir. The way you explain questions helps me a lot to understand and build up logic.
Thanks bro so much !
@@takeUforward Didn't expected to get a reply. Welcome Sir
@@takeUforward when u solved this for the very first time, were u able to devise this algo on ur own or u had to look at some resource?
Very Nice Explaination
Prabhu Charan kahan hain aapke....?? NAILED IT BRO!!!
Thanks for the intution ! Gfg blogs are meant for rot learning these days
Wow I was able to solve it on my own after I understood the intitution
This video provides the most intuitive and easy way to solve the problem :)
I can say one word ,You are awesome!
Understood! Amazing explanation as always, thank you very much!!
watched many videos of yours, but now before watching any new videos I priorly hit like!! :) bcz this channel had won my emotions in coding. great going thanks man!!
hats off to your way of explanation! understood :)
You explained it so well. Understood it after listening once.
What if there are duplicates which are greater than your pivot.?
Which one will you choose?
starting one or last one?
and why?
Consider this case: [2,3,1,3,3]
answer will come by choosing the right one..
but why?
Jhakas !! kya explain kiye striver bhaiya !!
BHai ur hardWork and dedication to teach us gives me a lot of hope To Study Hard ... thankU 👍
It's my pleasure
so if array is 1,2,4,3,5
id1=1
traversing from right
id2=4
swapping 1,5,4,3,2
reversing from id1+1 =>1,5,2,3,4
which is wrong
o/p->1,2,4,5,3
.
.
.
.
traversing from right find the breaking point say id1
find next greater element from id1+1 to len(arr)-1 say id2
swap id1,id2
reverse from id1+1 to len(arr)-1
Thank you Striver
Bhai aag laga di ladke ne
Hello!
I guess the complexity should be O(nlogn) as we are reversing the array.
we are reversing ,not sorting. so tc=o(n)
G.O.A.T explanation for this prob!!! 🐐
understood ..Top notch as always
I did this question today ....what an intuition Bhaiyya...really great explanation😊😊🙏🙏
Very Nice Explanation........Keep making videos
That is the solution I am looking for, Thnx!
Brilliantttttttt Explanationn!! Loving this series!!!
Great explanation.
Your explanation is best 🔥
instead of using second loop (to the just greater value ).can we use upper_bound stl ??
solving the DsA 450 , this is the best one you explained so far
How many did you solve till now
Yo seems like death note fan but aot>death note
Thank you strver bhai
Best explanation available on UA-cam for this problem statement.Great work sir..
Thanks for such a clear explanation
Thank you sir
once i get job ill join ur channel for sure
Best explanation!!
Excellent!!!!!!!!!!!!!!!!!!!!
No words man
Just amazing. Really respect you sir.. Hats off to your hard work!
jod❤🔥 thank you striver for this much good explanation
easiest explanation. Thanks a lot man
This is next level explanation❤❤💥💥
Nice explaination. You made it very easy to understand 🔥
Glad it helped!
@striver 1 3 5 2 4 is not increasing from both backward and forward
Sir ,nice to have such videos , please keep this placement series going.
Superb explanation❤
Hii, Your way of explaning is really good. Could you please make a video on smallest sufficient team leetcode problem.
Hiii
Broooo! You're the best! 😍
This is just a beautiful question and an amazing explanation
ur just fab bhaya. never stop .
Thanks a lot Striver for such a beautiful explanation!!
Such a nice Explanation😃
love you so much striver bhaiya
Good intuiton explanation.
Mind blowing explanation 🤯🤯. Thanks striver ❤
A very much thank you 🥰
what an amazing explanation!!