Next Permutation | Google | Microsoft | Amazon | Leetcode 31
Vložit
- čas přidán 18. 07. 2022
- In this video, we will see another popular Array Question "Next Permutation".
Problem Name : Next Permutation
Leetcode Link : leetcode.com/problems/next-pe...
GfG Link : practice.geeksforgeeks.org/pr...
My solutions on Github : github.com/MAZHARMIK/Intervie...
Company Tags 😱🤯 : Amazon, FactSet, Hike, Amazon, MakeMyTrip, Qualcomm, Infosys, Microsoft, Google, Salesforce, Flipkart
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : czcams.com/channels/aw5.html...
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 ❤️❤️❤️🙏🙏
Whenever i search for a question and this channel comes up . feels good.
Very welll explained never seen before
I gone through various videos
Finally I found you & got better understanding with better story
😇🙏
Gola suspence during the solution was far greater than any netflix web series cliffhanger😂😂
😁😅 ❤️🙏
Hope the video helped 😇
You explained really well. Thank you!!
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 ❤️❤️❤️
I have done same approach...first write stiry then code
Great explanaation my friend
best explanation so far
Great as always 🎉
Best explanation with intuition 🤩
Thanks
easily explained!!
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.
Thanks for your efforts, loved your explanation ❤❤
My pleasure 😊
hey sir , I have Infosys Specialist interview. Can you suggest me topics I should brush up before interview
Sir its give TLE (time limit exceed)
With your solution in java
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
Bhaiya sab kuch clear ho gya. Hats off. aapki linked in id milegi kya?
Easy Explaination>>>> :):):)
Thank you 🙏😇
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 please leetcode 567 bhi krwa dijiye
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]
Day 2
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 💪
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 :) )
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]
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
//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]
Ek mahine phele hi kiya tha yehi video dekh kar aur aaj ekdum sab bhul gaya 😮💨🥲
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
//{ 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