Your intuition approach is so good that I'm afraid can not find anywhere on the internet, some programming education nowadays is kind of distorted by just do it for trend and profit. High quality and dedicated contents are so underrated in my opinion. Again thanks a billion for your great work and dedication! Understood!
Just in case ur confused, //find the first adacent pair from right side where left is smaller than right //if you dont find such a pair, reverse the whole array //swap the left element in the pair with the smallest element greater than that to its right //then reverse the sub array from the point of swap(after the left element in the pair) till the end
Very good understanding, but in last point you should edit reverse to sort. Because you should sort the sub array from the point of swap(after the left element in the pair) till the end and not reverse from that point. Cause you need the smallest value from those numbers. Not something random by revrseing them.
Just something i would like to point out At 18:46 he says to place the remaining elements in sorted order. Now a rookie like me would go about using something like sort(A.begin() + ind + 1, A.end()), but he never said to sort that segment just to place them in sorted order and he observed that the remaining elements are decreasing so he chose to reverse instead of sort because that would take only O(n) time whereas sorting that segment will take O(n^2) time (Worst case quicksort) this just shows his experience and for how long he has been doing this. Hats off bro you're one of the reasons people are improving in understanding these concepts and these little but powerful observations on the side.
@@kuldeepsinghthakur5778 the remaining segment will Always be in decreasing order. Watch the part where he's talking about the "dip" at 20:13 for more clarity.
I started Learning DSA after 10+ years experience in the industry.. Really appreciate your effort to give it back to community...Keep it up .. have a great success in future endeavours
Understood. Thank you so much for your dedication strive it is very inspiring, I am solving this at 12:02 on a sunday night because I have seen how hard you work to produce these videos, Thanks a lot.
Are you also studying DSA from this section of the video? If you are, would you be interested in learning together? Please let me know if you're open to learning together.
I am beginner at DSA and I have gone through the same problem of yours from Array series 2-3 times but intuition was not being clear. But this video has cleared in first few minutes. Thank you so much. This A2Z DSA course is world's best course. You have made one the complex topic in IT industry very easy for the world.😍
I have always tried to avoid this question because I was unable to digest its solution, but I will recommend all the new users to please watch the solution till end, you will get to know why Striver is the God of coding world. Wonderful channel , wonderful content... To all my fellow learners : Bus yahan se padhlo naukari pakki hai tumhari!! Naukri hai toh promotion pakka!!! Thank you v. much Striver
@@savage4493 No, because I was not able to grasp the knowledge, I just used that Stl library to solve this, but now I'm confident enough to write its logic.
@@harsha4048 first you are looping from backward and checking condition a[ i ] < a[ i+1 ] (so here is dry run a[ i ] < a[i+1] == a[ 4 ] < a[5 ] hear 4 and 5 are index which means a[ 4 ] = 3 and a[5 ] = 0 that means 3 < 0 ( hear its not meet the if condition so it wont go inside the if block ) it will satisfy the if condition only at index 1 { a[1] = 1 and a[i +1 ] = 5} , i hope you get it..
wow seeing all the comments i am very glad i got stuck in this problem and gave 2 days of time to think solution of this problem on my own on free time while also solving other problems, and got the exact approach on my own lol idk how @@pragatisrivastava8051
LIiterally the observation you tried to explain is superb and code it my own once observation is clear cut anyone can code it by its own if he know programming language.
Hats down the best video on this topic on the entire internet, was never able to understand this problem but after watching this video everything became so easy.
u just crushed the competition in programming...not any company or any Individual could think to release such a great content in the market. before they could think ..broo launched it 😂😂..feeling proud of learning programming in striver era..🔥🔥
Man Your teaching is fantastic even after buying a course for dsa i wasn't able to understand concept this better that you are providing free. Such A Gem Teacher....!
Hey!! Thank you so much for your awesome explanations . I really understood the intuiton and the problem was awesome too .. Waiting for your further lectures !!
1. Longest prefix match, find the break point : a[i] < a[i+1] 2. find > A, the next greater element but smallest one from the right side. So that you stay close. If break point does not exist: reverse the whole array. 3. Swap the break point and the smallest greater element. 4. Place the rest of the elements in the increasing order. (ascending order)
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.
Hi Raj Bhaiyan, Here I am watching till at 1:35 AM since last 1.5 hrs, Great intuition you build before teaching algorithms directly. That's a great way. If i will teach algorithm to anyone i will follow the same approach. 🙏🙏
@@Sharath_Codm because he need to provide very next permutation , hence before reversing the right half , he need to swap with ind such that even he swapped , if you observe array from right half it still increases and then decreases at breakpoint. Hope this clears your query.
i like how striver explains everytime what does the term brute force solution mean for anyone who is new to the channel. bro gives 110% efforts. not bro actually i am 19 , sir
HOPE I HAD WATCHED THIS QUESTION BEFORE MY GOOGLE INTER INTERVIEW, THE QUESTION WAS HAVING ALL POSSIBLE PERMUTATIONS AS PART OF BIGGER QUESTION BUT I JUST CONSUMED A LOT OF TIME TO THINK ON MY OWN. WILL, I WASN'T FULLY PREPARED THEN BUT I WILL MAKE SURE I WILL BE FOR THE NEXT ONE ! :)
Your way of explanation and delivering the way to solve the problem gives me a perfect idea on how to solve the problem without seeing the coding part. Thank you bhaiya for such an amazing series.😄
Please watch our new video on the same topic: th-cam.com/video/JDOXKqF60RQ/w-d-xo.html
this is the same video??
areee
thanks for the vid😄😄😄😄
Bro took recurrsion very seriously.😅
Recursion 😅, it is the same video's link
Brute -> 3:25
Optimal -> 7:35 obj2: 16:14 logic summary: 18:57 algo 19:31
your're time saver thanks bro
why in for loop i=n-2
why not i =n-1
Truly, humans like you are so much talented and generous to share their knowledge.
And AGI won't be this generous 🔥
@@parthsalatIt's far more generous
Let's march ahead, and create an unmatchable DSA course! ❤
Use the problem links in the description.
Thanks bhaiya, great explaination.
I was waiting for this video I know you are busy but please try to upload alternate days....
** Timestamps **
0:42 Explaination of what problem says
3:26 Brutforce approach
6:45 Better approach
7:22 Optimal approach
24:58 Code
@@leoved1073 I was not doing well, the body took a toll.
Great explanation ❤️
Your intuition approach is so good that I'm afraid can not find anywhere on the internet, some programming education nowadays is kind of distorted by just do it for trend and profit. High quality and dedicated contents are so underrated in my opinion. Again thanks a billion for your great work and dedication! Understood!
I have been on your page for the past couple of days. Thanks for all you do we miss you
GOD LEVEL EXPLANATION, BUT HOW IN THE EARTH WE ARE SUPPOSED TO THINK A SIMILAR LOGIC BY TRYING OURSELVES!!!
practice practice practice
@@ManujChaudhari001 Chup
@ practice practice practice practice practice
Just in case ur confused,
//find the first adacent pair from right side where left is smaller than right
//if you dont find such a pair, reverse the whole array
//swap the left element in the pair with the smallest element greater than that to its right
//then reverse the sub array from the point of swap(after the left element in the pair) till the end
Very good understanding, but in last point you should edit reverse to sort. Because you should sort the sub array from the point of swap(after the left element in the pair) till the end and not reverse from that point. Cause you need the smallest value from those numbers. Not something random by revrseing them.
@@shekharsharma3331 no need of sorting because after swapping also this part of the array is still sorted. No point of sorting it again
Understood very well. This is the ultimate sheet everyone needs!! Thank you for making such kinda premium content for absolutely free🤩🤩🤩
At first, it was difficult to understand but after watching it again, it is crystal clear
Just something i would like to point out
At 18:46 he says to place the remaining elements in sorted order. Now a rookie like me would go about using something like sort(A.begin() + ind + 1, A.end()), but he never said to sort that segment just to place them in sorted order and he observed that the remaining elements are decreasing so he chose to reverse instead of sort because that would take only O(n) time whereas sorting that segment will take O(n^2) time (Worst case quicksort) this just shows his experience and for how long he has been doing this. Hats off bro you're one of the reasons people are improving in understanding these concepts and these little but powerful observations on the side.
will the remaining segment always be in decreasing order, and if not why did he not fail in the submission with the test values?
@@kuldeepsinghthakur5778 the remaining segment will Always be in decreasing order. Watch the part where he's talking about the "dip" at 20:13 for more clarity.
Your explanation was excellent 👍👍👍🙏🙏🙏 but what I find more impressive is you can do this at 3am in the morning 👍👍👍👍
He doesn't live in india it might be 10 pm for him
@@Ahsan-y4r Mob shows local time zone only, if he is in India or US dosent matter,the time he recorded this vidoe was 3 am only...
Who said
I started Learning DSA after 10+ years experience in the industry.. Really appreciate your effort to give it back to community...Keep it up .. have a great success in future endeavours
Can you guide what is demand of the industry from freshers ? Please it will be helpful
I appreciate your hard work, thanks for making these valuable videos for free.
Watching this at 1.17 am and have to go to work tomorrow at 8 am. Hopefully this all will be worth it!
Understood. Thank you so much for your dedication strive it is very inspiring, I am solving this at 12:02 on a sunday night because I have seen how hard you work to produce these videos, Thanks a lot.
Best explaination of this question in coding community.No one can explain intitution as striver can explain . striver you are legend.
The best explanation I could have ever asked for. Thank you, Sir.
a channel which can be subscribed without any hesitation or doubt. loving the depth of explanation ❤
waited for this question's intuition video thank you striver for doing this.
Understood! Wow!! Super amazing explanation as always, thank you very very much for your effort!!!
He is made for this ...
Striver!! Truly you are made to teach DSAlgos!!!!
Hats off ❤
Are you also studying DSA from this section of the video? If you are, would you be interested in learning together? Please let me know if you're open to learning together.
I am beginner at DSA and I have gone through the same problem of yours from Array series 2-3 times but intuition was not being clear. But this video has cleared in first few minutes. Thank you so much.
This A2Z DSA course is world's best course. You have made one the complex topic in IT industry very easy for the world.😍
Did you finish this A2Z DSA Series..?
@@yashpaunikar671 Did you?
Understood. A very good lecture tbh, the way you walked us through the approach, just loved and enjoyed it. Thanks Striver
I have always tried to avoid this question because I was unable to digest its solution, but I will recommend all the new users to please watch the solution till end, you will get to know why Striver is the God of coding world.
Wonderful channel , wonderful content...
To all my fellow learners : Bus yahan se padhlo naukari pakki hai tumhari!! Naukri hai toh promotion pakka!!!
Thank you v. much Striver
avoid this question so do you mean that you try and solve the qsns before watching tutorials? is that the right approach?
@@savage4493 No, because I was not able to grasp the knowledge, I just used that Stl library to solve this, but now I'm confident enough to write its logic.
Can you explain the logic of the code
21:32
@@harsha4048 first you are looping from backward and checking condition a[ i ] < a[ i+1 ] (so here is dry run a[ i ] < a[i+1] == a[ 4 ] < a[5 ] hear 4 and 5 are index which means a[ 4 ] = 3 and a[5 ] = 0 that means 3 < 0 ( hear its not meet the if condition so it wont go inside the if block ) it will satisfy the if condition only at index 1 { a[1] = 1 and a[i +1 ] = 5} , i hope you get it..
wow seeing all the comments i am very glad i got stuck in this problem and gave 2 days of time to think solution of this problem on my own on free time while also solving other problems, and got the exact approach on my own lol idk how @@pragatisrivastava8051
This guy is a legend
This is the greatest explanation I've ever seen, esp. the idea around 17:00.
Wow, hats off! This is one of the best explanations, that got through my head. Thanks man.
LIiterally the observation you tried to explain is superb and code it my own once observation is clear cut anyone can code it by its own if he know programming language.
Thank you for this one. There aren't many resources out there that explain this the way you do. Wishing you the best, and keep up the good work!
Have been waiting for ur video for the past 3 days
Understood!! Nicely explained Striver!! Thank you so much 😊
Hats down the best video on this topic on the entire internet, was never able to understand this problem but after watching this video everything became so easy.
i was not getiing the problem but now just one thing, u r just awesome
u just crushed the competition in programming...not any company or any Individual could think to release such a great content in the market. before they could think ..broo launched it 😂😂..feeling proud of learning programming in striver era..🔥🔥
What an explaination, loved the way Striver explains
The question was quite complex, but you made it easy, Thank you!
very well explained I just loved it
Highly influenced by the intuition and the way he taught in the lecture😘
Absolutely amazing explanation of the intuition
Man Your teaching is fantastic even after buying a course for dsa i wasn't able to understand concept this better that you are providing free. Such A Gem Teacher....!
What a great explanation! Crystal clear!❤
Excellent intuition building teaching... Salute to the hard work.🧑💻
Very well explained the intuition and how the algorithm works, thank you for your great efforts.
Understood...Thank You So Much for this wonderful video......🙏🙏🙏
Feel a gaya concept smajh kar... best explanation thank you bhaiya
Hey!! Thank you so much for your awesome explanations . I really understood the intuiton and the problem was awesome too .. Waiting for your further lectures !!
1. Longest prefix match, find the break point : a[i] < a[i+1]
2. find > A, the next greater element but smallest one from the right side. So that you stay close.
If break point does not exist: reverse the whole array.
3. Swap the break point and the smallest greater element.
4. Place the rest of the elements in the increasing order. (ascending order)
Directly went into my brain. Thank You So Much for your clear understanding!
Concept is superb explain...I pause the video in middle of it press the like button and then continue..👍
3:25 // Brute Force Approach
class Solution {
private:
void getPermutation(vector nums, int index, set &ans){
if(index == nums.size()){
ans.insert(nums);
return;
}
for(int i = index; i < nums.size(); i++){
swap(nums[index], nums[i]);
getPermutation(nums, index+1, ans);
swap(nums[index], nums[i]);
}
}
public:
void nextPermutation(vector& nums) {
vector res = nums;
sort(nums.begin(), nums.end());
int n = nums.size();
set s;
int index = 0;
getPermutation(nums, index, s);
vector ans(s.begin(), s.end());
if(ans.size() == 1) {
nums = res;
return;
}
int i;
for(i = 0; i < ans.size(); i++){
bool check = true;
vector temp;
for(int j = 0; j < ans[i].size(); j++){
temp.push_back(ans[i][j]);
}
if(temp == res) break;
}
int fac = ans.size();
nums.clear();
if(i+1 == fac){
nums = ans[0];
}
else{
nums = ans[i+1];
}
}
};
If you first write the code then difficult to understand,
But after EXALLENT explanation it becomes easy to understand ❤❤❤
Hey Striver, the explanation is amazing. Thank you so so so much!!
I wonder how you come up with these ways to explain 😅
Superb explaination !! Speciality of striver bhaiya is that he focus more on the intution than algorithm. Thanks bhaiya
I was sure that it was the best channel for DSA 100%
What a wonderful explanation, thank you so much for explaining everything from one corner to another. ❤
absolutely genius ,the way you explained everything
You can do binary search in brute force second step
Thanks a lot, brother. Love and Respect from Bangladesh
This is one of the best Logic I came across
the god of explaining complex algos..🙏🙏🙏
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.
This was explained very beautifully. Thanks striver
Damn, dude, that explanation was just simply on some next level.
At some moment i feel that i came back to my childhood where i am learning alphabets, A for apple ,B for ball, C for coding 🙂.
Best Explanation Ever.. Thank You So Much for all the Efforts. 🍀❤🔥🔥
Hi Raj Bhaiyan, Here I am watching till at 1:35 AM since last 1.5 hrs, Great intuition you build before teaching algorithms directly. That's a great way. If i will teach algorithm to anyone i will follow the same approach. 🙏🙏
He has this little south indian accent when he's trying to explain something whole heartedly. It's wholesome and a bit funny. Love the sheet ❤
Haha yes I do have
I'm student of mnit Jaipur and I'm watching your vedio for presentation DSA . And apke vedio banane ka tarika aur padane ka tarika opp hai Bhaiya
Legend Bro , really building up my concepts step by step . Shout out to TUF Team 💯
Bro why he swapped ?
@@Sharath_Codm because he need to provide very next permutation , hence before reversing the right half , he need to swap with ind such that even he swapped , if you observe array from right half it still increases and then decreases at breakpoint. Hope this clears your query.
Understood Bro! Heartful Thanks for you!
Understoooood 😃.
Learning DSA from u is so easy and fun
Hats off to you striver
Truly admirable! Your dedication level is worth emulating.
What a explanation skill you have bro.
Thanks for quality content .
Really thankful and appreciate ur effort striver thanks a million! 👏
I did the same problem from your sde sheet but implementation was bit hard there 🙃🙃now it's like cake walk ❤❤❤❤ thankyou #striver🎉
Great explanation of the intuition, Understood 🔥
@striver, you are a God in DSA. I Salute you bro!!! Thanks for all you do for us
Thanks for telling that we should not dive deep into the brute force sol. in an interview
Amazing Video,
Got the concept completely,
Thank You, Sir,
May god bless you,
I am your mentee now
That's really fantastic. Amazing 🔥🔥Thankyou Striver. Leetcode problem is done by myself.
Had to go over it twice but understood it now!
One of the best explained solution. Thanks for the content
second for loop can take i till i>index no need of =
understood , this is the best channel ever.
Kya hi samjhaya hai bhai. Killed it.
i like how striver explains everytime what does the term brute force solution mean for anyone who is new to the channel. bro gives 110% efforts. not bro actually i am 19 , sir
WOW! What an explanation! Genius.
Thanks!
just awesome...mja aa gya 🥳🥳
Very very easy to understand.
Great explanation.
Thanks a lot.
understood, extremely good explanation!
HOPE I HAD WATCHED THIS QUESTION BEFORE MY GOOGLE INTER INTERVIEW, THE QUESTION WAS HAVING ALL POSSIBLE PERMUTATIONS AS PART OF BIGGER QUESTION BUT I JUST CONSUMED A LOT OF TIME TO THINK ON MY OWN. WILL, I WASN'T FULLY PREPARED THEN BUT I WILL MAKE SURE I WILL BE FOR THE NEXT ONE ! :)
amazing explanation . the way you explained it is phenomenal.
SDE Sheet: Day 1 Problem 3 Done!
Mind blowing 🗿🔥🔥
Your explanation is so good,I can understand easily👌🔥
Your way of explanation and delivering the way to solve the problem gives me a perfect idea on how to solve the problem without seeing the coding part. Thank you bhaiya for such an amazing series.😄
you are just mind blowing sir!
Understood bhaiya. Hats off to your dedication.
Great content with complete explanation, You explain the algorithm from basics