Next Permutation | Google | Microsoft | Amazon | Leetcode 31
Вставка
- Опубліковано 8 січ 2025
- In this video, we will see another popular Array Question "Next Permutation".
Problem Name : Next Permutation
Leetcode Link : leetcode.com/p...
GfG Link : practice.geeks...
My solutions on Github : github.com/MAZ...
Company Tags 😱🤯 : Amazon, FactSet, Hike, Amazon, MakeMyTrip, Qualcomm, Infosys, Microsoft, Google, Salesforce, Flipkart
My GitHub Repo for interview preparation : github.com/MAZ....
Subscribe to my channel : www.youtube.co....
One of the best channels for understanding dsa concepts!❤
isse behtar explaination ho hi nhi sakta iss cheez ka
100% effort from your side .... such a good teacher .....Thank you so much sir 🙏🙏🙏
Means a lot ❤️❤️❤️🙏🙏
You are super awesome bhai. I have 15+ years of experience but I can not do better than you. I am here to learn from you. Thank you so much 🙏🙏🙏🙏
This means a lot 😇❤️🙏
wow
I gone through various videos
Finally I found you & got better understanding with better story
😇🙏
I think this is the only best explanation out there for this problem. I watched the explanation on this of other famous youtubers, but this legend is on another level. hats off
gola_index hits hard 😅
🤣 awesome. I like the way you name things in code like 'gola_index", blue gola etc. Nobody has done this before. You have set new trend, I really like it. Plus it is so intuitive. Great video.
Glad you liked it!🙏❤️😇
Whenever i search for a question and this channel comes up . feels good.
Brilliant, just brilliant. The way you setup the story, it's sank deep in my soul. Now I will not forget it.
It's my first video on your Channel, Thanks, Subscribed!
Means a lot. Thank you ❤️❤️❤️
Your channel should grow to infinite subscribers . Each and every video is great . Wow .
Wonderful keep up the good work, GURUJI.
gola_index took me by surprise XD. Beautiful explanation.⚡
Very welll explained never seen before
Gola ke karan bahut acche se samjh me aa gaya❤
I literally give 1:30 hours for code after your intitution but not it run 180 cases but failed at 181 cases when i got frustated then i watch your code. ab aaj ke liye kafi hai bahut hua aaj ka .totally exhausted.
It’s totally fine to take breaks and relax your mind. Take rest and then comr back tomorrow with more motivation and let’s do it 💪
Gola suspence during the solution was far greater than any netflix web series cliffhanger😂😂
😁😅 ❤️🙏
Hope the video helped 😇
gola_index zindabad 😅 can't stop laughing. Amazing explanation bhaiya as always.
I got this question in one of my interview, but still find difficult to identify the solution. I feel its hard to crack this approach in real interview scenario.
Thanks for explanation
//java
class Solution {
public void nextPermutation(int[] nums) {
int i=nums.length-1;
while(i>0 && nums[i]0){
int j=nums.length-1;
while(j>0 && nums[j]
best explanation so far
int gola_index = 0, lmao, you win over me there
Thanks for your efforts, loved your explanation ❤❤
My pleasure 😊
Best explanation with intuition 🤩
I think good example would be take [1,4,3,2] here you have to swap 1 with 2 not with 4 as it's bit misleading from your concept but I understood it thanks for explanation
You explained really well. Thank you!!
Great as always 🎉
Easy Explaination>>>> :):):)
Thank you 🙏😇
Great explanaation my friend
I have done same approach...first write stiry then code
luv u sir may god bless you
Gola index and swap index🔥✅
Awesome
Sir its give TLE (time limit exceed)
With your solution in java
//{ Driver Code Starts
// Initial Template for C++
#include
using namespace std;
// } Driver Code Ends
//User function template for C++
class Solution {
public:
void multiply(vector&arr, int multiplier){
int carry = 0;
for(int i=0; i< arr.size(); i++){
int res = multiplier*arr[i];
res = res+carry;
arr[i] = res % 10;
carry = res/10;
}
while(carry > 0){
arr.push_back(carry%10);
carry = carry / 10;
}
}
vector factorial(int N){
vectorarr;
arr.push_back(1);
for(int multiplier = 2; multiplier= 0; i--){
result.push_back(arr[i]);
}
return result;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int N;
cin >> N;
Solution ob;
vector result = ob.factorial(N);
for (int i = 0; i < result.size(); ++i){
cout
easily explained!!
video was awesome but i have a doubt when we are finding just a larger element then it is possible that we can get larger element but not just larger than an element
Bhaiya sab kuch clear ho gya. Hats off. aapki linked in id milegi kya?
how would we find last permutation (ie previous one) ?
if [1,3,2,1,3] then last premutation would be [ 1, 3, 1, 3, 2]
hi, great explanation, but I just have one question, while finding the swap index how can we be guaranteed that the first element we find is the just greater one , cant we have a condition where the element is greater but not just greater???? pls answer.
Because if the first next greater element is which comes first , because if it is not possible then gola index changed , it will always come first ,dry run you will understand because
hey sir , I have Infosys Specialist interview. Can you suggest me topics I should brush up before interview
🙏🙏♥️♥️
Thanks
bhiya questions karna ka sahi approach kya hona chiya apka videos dekh kar dubara woo question attempt karna is it a correct way??
Jb hum search krre h gola se just bada kse ap keh skte hai ki gola index se last wala element bada bich me bi to ho skta hai na.
Ex gola is 3 and last element of array is 7 to gola se just bada mil gya but in dono k bich me 4 h jo ki apke code k according keese chlega please koiii btana ❤
nope because ham gola index hi aese le rahe ki piche se jo bada ele aayega vo 100% just bada hi hoga
tumhara case hi glt he aesa hoga hi nahi bich me char aa hi nahi skta
imam sir , i have a doubt , pls reply , actually i encountered this problem a week ago and tried and saw ur soliution and completely understood it , and today when i tried solving it again , i am not able to do it , i just forgot everything u taught , i dont know what is happening , and this is happening very often , like i want to know m, why this is happening and what is the correct way of learning , like i saw your video learned it , but later forgot so i am not able to learn to code n do dsa o properly , can u teach me the way to learn , where am i lacking in this method ,??
keep revising the questions, forgetting implementation in the beginning is very common in dsa, it happens with everyone, just try to do revision in short intervals, eventually you will be able to retain the concept.
Ek mahine phele hi kiya tha yehi video dekh kar aur aaj ekdum sab bhul gaya 😮💨🥲
@HimanshuPatel abhi try kr😂
Bhaiya please leetcode 567 bhi krwa dijiye
algorithm smjh m aagya kese krna h pr ye intuition kese aaya wo pta nai lg rha .. ki hm right side s q smaller element dekhege .. iss logic p kese phoche
ummm. I got it wrong initally. Phale I thought I have to swap with min or max element... then I realized ki at the time of swapping (which is the next permutation) - I must swap myself with the next element larger than me.
Going from left won't work as the left most element is highest element and there maybe smaller permutations down the line. So first have to explore smaller permutations and only then explore the longer permutations.
hope this helps. this question was tough (for me :) )
Cfbr
Day 2
bhaiya mera aur apka approach thoda similar , what i did i find that index but now what i did is that i try to find smaller element and swap with goal_index-1 and then just sort the remaining array from gola_ind to last
Thanks for sharing Sidharth
someone explain the logic why this works
question khatam kab ho gaya pata hi nahi chala
sir to be honest I cannot understand that gola wala part can u explain to me i have watched it multiple times
Gola wo element hai jo iss condition ko satisfy kar raha hai... Arr[n-1] < Arr[n]
How u find the condition arr[i-1] < arr[i]
Hi Zaviya,
Actually it’s totally based on
1) observation
2) Seeing how words are ordered in dictionary lexicographically
I usually do multiple of dry run and take multiple examples. It helps to figure out patterns (if any) that can help to solve qns