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.
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.
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.
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
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.
Approach:start from end of areay and keep decreasing till you are getting increasing number ,now you have to substitute at that place smallest number and sort the array
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....!
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..🔥🔥
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 !!
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 ! :)
#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.
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
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.
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
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
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!
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 ❤️
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
I have been on your page for the past couple of days. Thanks for all you do we miss you
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
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
Understood very well. This is the ultimate sheet everyone needs!! Thank you for making such kinda premium content for absolutely free🤩🤩🤩
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.
GOD LEVEL EXPLANATION, BUT HOW IN THE EARTH WE ARE SUPPOSED TO THINK A SIMILAR LOGIC BY TRYING OURSELVES!!!
practice practice practice
I appreciate your hard work, thanks for making these valuable videos for free.
At first, it was difficult to understand but after watching it again, it is crystal clear
waited for this question's intuition video thank you striver for doing this.
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.
This is the greatest explanation I've ever seen, esp. the idea around 17:00.
Watching this at 1.17 am and have to go to work tomorrow at 8 am. Hopefully this all will be worth it!
This guy is a legend
a channel which can be subscribed without any hesitation or doubt. loving the depth of explanation ❤
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.
Have been waiting for ur video for the past 3 days
Understood. A very good lecture tbh, the way you walked us through the approach, just loved and enjoyed it. Thanks Striver
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.
What an explaination, loved the way Striver explains
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?
i was not getiing the problem but now just one thing, u r just awesome
Feel a gaya concept smajh kar... best explanation thank you bhaiya
Absolutely amazing explanation of the intuition
Superb explaination !! Speciality of striver bhaiya is that he focus more on the intution than algorithm. Thanks bhaiya
Wow, hats off! This is one of the best explanations, that got through my head. Thanks man.
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!
Excellent intuition building teaching... Salute to the hard work.🧑💻
The question was quite complex, but you made it easy, Thank you!
Understood!! Nicely explained Striver!! Thank you so much 😊
What a great explanation! Crystal clear!❤
This was explained very beautifully. 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
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.
Very well explained the intuition and how the algorithm works, thank you for your great efforts.
the god of explaining complex algos..🙏🙏🙏
Approach:start from end of areay and keep decreasing till you are getting increasing number ,now you have to substitute at that place smallest number and sort the array
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....!
You can do binary search in brute force second step
I was sure that it was the best channel for DSA 100%
Understood...Thank You So Much for this wonderful video......🙏🙏🙏
very well explained I just loved it
Highly influenced by the intuition and the way he taught in the lecture😘
absolutely genius ,the way you explained everything
Understood Bro! Heartful Thanks for you!
Directly went into my brain. Thank You So Much for your clear understanding!
Great explanation of the intuition, Understood 🔥
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];
}
}
};
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..🔥🔥
Damn, dude, that explanation was just simply on some next level.
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 !!
Thanks a lot, brother. Love and Respect from Bangladesh
This is one of the best Logic I came across
Overall intuition: 19:25
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 ! :)
If you first write the code then difficult to understand,
But after EXALLENT explanation it becomes easy to understand ❤❤❤
#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.
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
Truly admirable! Your dedication level is worth emulating.
What a explanation skill you have bro.
Thanks for quality content .
SDE Sheet: Day 1 Problem 3 Done!
I will make sure that atleast from here I will comment something, bare minimum "thank you" for such great help
Concept is superb explain...I pause the video in middle of it press the like button and then continue..👍
Thanks!
Very very easy to understand.
Great explanation.
Thanks a lot.
amazing explanation . the way you explained it is phenomenal.
just awesome...mja aa gya 🥳🥳
thank you so much for your efforts sir
One of the best explained solution. Thanks for the content
you are just mind blowing sir!
@striver, you are a God in DSA. I Salute you bro!!! Thanks for all you do for us
God level teaching
Kya hi samjhaya hai bhai. Killed it.
understood , this is the best channel ever.
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
understood, extremely good explanation!
Understoooood 😃.
Learning DSA from u is so easy and fun
Hats off to you striver
What a wonderful explanation, thank you so much for explaining everything from one corner to another. ❤
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
Really thankful and appreciate ur effort striver thanks a million! 👏
Mind blowing 🗿🔥🔥
Understood bhaiya. Hats off to your dedication.
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. 🙏🙏
WOW! What an explanation! Genius.
by the way your explanation is truly amazing..!!!
Very clearly explained. Thank you ❤
Great content with complete explanation, You explain the algorithm from basics
Amazing Video,
Got the concept completely,
Thank You, Sir,
May god bless you,
I am your mentee now
Thank you for making it super easy to understand!
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.
Thanks for telling that we should not dive deep into the brute force sol. in an interview
Best Explanation Ever.. Thank You So Much for all the Efforts. 🍀❤🔥🔥
Understoood....This video was much awaited..
Good intution building. It seems very simpler with your approach :)