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....

КОМЕНТАРІ • 73

  • @SubhranilDas-bo6ic
    @SubhranilDas-bo6ic 9 місяців тому +17

    One of the best channels for understanding dsa concepts!❤

  • @ratishjain2718
    @ratishjain2718 11 місяців тому +20

    isse behtar explaination ho hi nhi sakta iss cheez ka

  • @rockykumarverma980
    @rockykumarverma980 Рік тому +19

    100% effort from your side .... such a good teacher .....Thank you so much sir 🙏🙏🙏

  • @kapilrules
    @kapilrules 3 місяці тому +4

    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 🙏🙏🙏🙏

  • @sapnokasahar3098
    @sapnokasahar3098 11 місяців тому +4

    I gone through various videos
    Finally I found you & got better understanding with better story

  • @aws_handles
    @aws_handles 13 днів тому +1

    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 😅

  • @Satya-g5t
    @Satya-g5t Місяць тому +2

    🤣 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.

  • @rv5778
    @rv5778 9 місяців тому +2

    Whenever i search for a question and this channel comes up . feels good.

  • @B-Billy
    @B-Billy 6 місяців тому +3

    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!

  • @shivam_prakash_0108
    @shivam_prakash_0108 2 місяці тому +1

    Your channel should grow to infinite subscribers . Each and every video is great . Wow .

  • @nitkarshchourasia2406
    @nitkarshchourasia2406 3 місяці тому +2

    Wonderful keep up the good work, GURUJI.

  • @priyajaiwal8072
    @priyajaiwal8072 25 днів тому +1

    gola_index took me by surprise XD. Beautiful explanation.⚡

  • @rohitsinghthakur3612
    @rohitsinghthakur3612 8 місяців тому +4

    Very welll explained never seen before

  • @ad_jha
    @ad_jha 4 місяці тому +1

    Gola ke karan bahut acche se samjh me aa gaya❤

  • @a3rdtierguy864
    @a3rdtierguy864 10 місяців тому +3

    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.

    • @codestorywithMIK
      @codestorywithMIK  10 місяців тому +5

      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 💪

  • @divsworld5925
    @divsworld5925 Рік тому +9

    Gola suspence during the solution was far greater than any netflix web series cliffhanger😂😂

  • @joydeep-halder
    @joydeep-halder 6 днів тому +1

    gola_index zindabad 😅 can't stop laughing. Amazing explanation bhaiya as always.

  • @komalsingla6032
    @komalsingla6032 8 місяців тому +2

    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

  • @Ark.01
    @Ark.01 6 місяців тому +4

    //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]

  • @zillakamisosmula570
    @zillakamisosmula570 11 місяців тому

    best explanation so far

  • @Ginger_Hrn
    @Ginger_Hrn Місяць тому +1

    int gola_index = 0, lmao, you win over me there

  • @technicalguy.
    @technicalguy. Рік тому +2

    Thanks for your efforts, loved your explanation ❤❤

  • @vinayjoshi8714
    @vinayjoshi8714 8 місяців тому

    Best explanation with intuition 🤩

  • @dipesh1401
    @dipesh1401 3 місяці тому

    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

  • @Rits2203
    @Rits2203 Рік тому

    You explained really well. Thank you!!

  • @rajshiromani727
    @rajshiromani727 8 місяців тому +1

    Great as always 🎉

  • @dataScience7845
    @dataScience7845 Рік тому +2

    Easy Explaination>>>> :):):)

  • @jyotirmaysingh4059
    @jyotirmaysingh4059 7 місяців тому

    Great explanaation my friend

  • @factStorybybong
    @factStorybybong 6 місяців тому

    I have done same approach...first write stiry then code

  • @samrudhshetty9334
    @samrudhshetty9334 4 місяці тому

    luv u sir may god bless you

  • @immrhrr
    @immrhrr 4 місяці тому

    Gola index and swap index🔥✅

  • @thefinalfit
    @thefinalfit 3 місяці тому

    Awesome

  • @lovegarg5061
    @lovegarg5061 6 місяців тому +1

    Sir its give TLE (time limit exceed)
    With your solution in java

  • @rode_atharva
    @rode_atharva 6 місяців тому +1

    //{ 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

  • @aggarwalsachin4854
    @aggarwalsachin4854 7 місяців тому

    easily explained!!

  • @VaishnaviHamde
    @VaishnaviHamde 11 місяців тому

    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

  • @ayusharyan2165
    @ayusharyan2165 Рік тому

    Bhaiya sab kuch clear ho gya. Hats off. aapki linked in id milegi kya?

  • @mitaleeminde8881
    @mitaleeminde8881 10 місяців тому

    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]

  • @pranavpranjal2717
    @pranavpranjal2717 5 місяців тому

    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.

    • @ayushranjan1507
      @ayushranjan1507 5 місяців тому

      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

  • @Bhavisshyya
    @Bhavisshyya 5 місяців тому

    hey sir , I have Infosys Specialist interview. Can you suggest me topics I should brush up before interview

  • @good114
    @good114 4 місяці тому +1

    🙏🙏♥️♥️

  • @somakbhuti9501
    @somakbhuti9501 6 місяців тому

    Thanks

  • @kritikajha1916
    @kritikajha1916 2 місяці тому

    bhiya questions karna ka sahi approach kya hona chiya apka videos dekh kar dubara woo question attempt karna is it a correct way??

  • @Xcoder__1957
    @Xcoder__1957 3 місяці тому

    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 ❤

    • @TarunGupta-f7s
      @TarunGupta-f7s Місяць тому

      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

  • @mayank1522
    @mayank1522 5 місяців тому

    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 ,??

    • @zehrarizvi8377
      @zehrarizvi8377 4 місяці тому

      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.

  • @HimanshuPatel-wn6en
    @HimanshuPatel-wn6en 7 місяців тому +4

    Ek mahine phele hi kiya tha yehi video dekh kar aur aaj ekdum sab bhul gaya 😮‍💨🥲

  • @jeethora586
    @jeethora586 6 місяців тому

    Bhaiya please leetcode 567 bhi krwa dijiye

  • @abcd76820
    @abcd76820 10 місяців тому

    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

    • @mrNanoDhruv
      @mrNanoDhruv 7 місяців тому

      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 :) )

  • @utkarshawasthi7748
    @utkarshawasthi7748 4 місяці тому +1

    Cfbr

  • @AnkitJain-w3l
    @AnkitJain-w3l 10 місяців тому

    Day 2

  • @sidharthdhiman4522
    @sidharthdhiman4522 Рік тому +1

    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

  • @fallenAngel-cw9ki
    @fallenAngel-cw9ki 4 місяці тому

    someone explain the logic why this works

  • @shreyxnsh.14
    @shreyxnsh.14 Місяць тому

    question khatam kab ho gaya pata hi nahi chala

  • @godwinv4838
    @godwinv4838 8 місяців тому

    sir to be honest I cannot understand that gola wala part can u explain to me i have watched it multiple times

    • @ayushpatel4710
      @ayushpatel4710 7 місяців тому

      Gola wo element hai jo iss condition ko satisfy kar raha hai... Arr[n-1] < Arr[n]

  • @zaviyakhurshid9097
    @zaviyakhurshid9097 2 роки тому +1

    How u find the condition arr[i-1] < arr[i]

    • @codestorywithMIK
      @codestorywithMIK  2 роки тому +6

      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