NEXT PERMUTATION | Leetcode | Know the Intuition behind the Algorithm | C++ | Java | Brute-Optimal

Поділитися
Вставка
  • Опубліковано 14 лис 2024

КОМЕНТАРІ • 420

  • @suryansh3809
    @suryansh3809 3 роки тому +563

    Thank you striver ❤️ got placed at paytm and this was the first question asked in interview 😍😍

    • @samirkumar9908
      @samirkumar9908 3 роки тому +8

      dude really?

    • @aandz6194
      @aandz6194 3 роки тому +15

      Brother inform us other questions as well through comments.....that would be helpful for us.....

    • @MrKingchamp1000
      @MrKingchamp1000 3 роки тому +20

      Gib Referral

    • @singhsahab9478
      @singhsahab9478 3 роки тому +21

      @@MrKingchamp1000 seppling rong viro

    • @BRSanush
      @BRSanush 3 роки тому +2

      @Suryansh did they ask intuition behind this problem.

  • @priyanshupandey6688
    @priyanshupandey6688 3 роки тому +63

    Just a suggestion, algo is quite easy but watch this video 2 or 3 times to get a clear picture of the intuition.
    Keep it up, brother.....!!!

  • @surajroy869
    @surajroy869 3 роки тому +9

    Only this guy can clear my doubt, I always search a problem and I’m feel blessing when he was already made video on that algorithm

  • @ashutoshtiwari4719
    @ashutoshtiwari4719 3 роки тому +190

    Trust me
    You won't get a better explanation than this one.🔥

    • @behindthescene4406
      @behindthescene4406 3 роки тому +1

      bro can u plz tell me y he said break point is the second last at 10:15

    • @pratapkumarchandra6488
      @pratapkumarchandra6488 3 роки тому +2

      @@behindthescene4406 the breapoint can be at 2nd last index in best case. hence it is better to iterate from that index

    • @asshwatthamaa1911
      @asshwatthamaa1911 3 роки тому +5

      @@behindthescene4406 if he will not iterate from second last then (i+1) will give array out of bound for (i= a.length-1).. that's why since we are comparing i with i+1.. we are starting from a.length-2

    • @a.yashwanth
      @a.yashwanth 2 роки тому

      check out back to back swe channel

  • @utsavsiddhpura8307
    @utsavsiddhpura8307 2 роки тому +3

    instead of swapping first, we can reverse first, then to find the first greater element we can use upper bound. Time complexity will be O(n + logn) = O(n) only but runtime will be fast.

  • @Gamer_with_knowledge
    @Gamer_with_knowledge 4 роки тому +39

    THIS IS ONE OF THE MOST UNDERRATED CHANNEL IN THE ASPECT OF CONTENT ..... DUDE YOU ARE ACTUALLY MAKING OUR FUTURE SECURE !! THANKS A LOT !!!

  • @chitranshsaxena59
    @chitranshsaxena59 3 роки тому +24

    My potato brain did not understand this even after watching the video twice

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

      even my potato brain cannot understand this bro , what to do 😂

  • @amanbhadani8840
    @amanbhadani8840 2 роки тому +7

    Never thought of these type of intuition,absolutely brilliant.

  • @sreejanagrahari
    @sreejanagrahari 4 роки тому +7

    I was stuck doing this question for many days but now u cleared my doubts .
    Thanks for your effort

  • @swapnoneelduttamajumdar5049
    @swapnoneelduttamajumdar5049 4 роки тому +32

    Thumbnails are becoming great day by day...

  • @AbhishekKumar-hk1gb
    @AbhishekKumar-hk1gb 4 роки тому +32

    Simply brilliant..
    I have not seen anyone explaining this beautifully.

    • @takeUforward
      @takeUforward  4 роки тому +4

      Thanks!! Cheers!!

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

      @@takeUforward sir, u said there will be inc and then dec sequence,but if it was asked find next perm of 213,there isn't incre/dec it's dec and inc ,how to find break point.

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

      ​@@sairam3351 reverse it bro

  • @user-nq7nt1rq9b
    @user-nq7nt1rq9b 2 роки тому

    after understanding the problem and the great explanation by striver
    also it tooks me 5-6 hourse literally
    if anyone wants the python code u can refer
    class Solution:
    def nextPermutation(self, N, arr):
    n = len(arr)
    if n = 0 and arr[i] >= arr[i+1]:
    i -= 1
    # ...
    if i < 0:
    # It shows that all the elements are in descending order.
    arr[:] = arr[::-1] #for reversing the array
    return arr
    else:
    # 2nd Step...
    j = n-1
    while arr[j]

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

    Small error at line 8 java code u have to put j>i along with & . Try this [1,3,1]

  • @JAYPRAKASH-uy8rg
    @JAYPRAKASH-uy8rg 4 роки тому +12

    The explanation of the intuition just blew me, wow man, just wow.🔥

    • @vinoths7140
      @vinoths7140 2 роки тому

      bro, Would you mind explaining what you mean by intuition when it comes to coding problems?

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

    striver, you are saving lives man!!

  • @NaveenKumar-zp4sy
    @NaveenKumar-zp4sy 3 роки тому +15

    Wow!!! Mind blowing explanation! That too in nearly 10 min! I love this series :)

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

    literally best video for next permutation, thanks

  • @Nikhil-ov6sm
    @Nikhil-ov6sm Рік тому

    I was watching this and thinking "there's no way there's any intuition to this" and was completely blown away by last..hats off

  • @saranshkumar4777
    @saranshkumar4777 2 роки тому +2

    In C++ Code ,if your Output is not matching just replace nums.begin()+k+1 in the end to nums.begin()+k. only it will give correct output.

  • @takeUforward
    @takeUforward  4 роки тому +42

    Please watch the new video which covers it in more depth, and also prints it: ua-cam.com/video/JDOXKqF60RQ/v-deo.html
    Better Explanation here: ua-cam.com/video/JDOXKqF60RQ/v-deo.html&lc=UgwUFtp9qorT4WtGZUR4AaABAg
    This video's explanation tends to fail for some, so prefer watching the above lecture.

    • @sahilchoudhary1473
      @sahilchoudhary1473 4 роки тому

      Understood !!

    • @AyushGupta-kb9iv
      @AyushGupta-kb9iv 4 роки тому

      Narayana Pandita's Algorithm...😊😊😊

    • @nithiya8418
      @nithiya8418 4 роки тому

      Understood bro! Thank you 😀

    • @ztrixx3280
      @ztrixx3280 4 роки тому

      Understood!
      Thank you :)

    • @cs208anjaysahoo2
      @cs208anjaysahoo2 4 роки тому +1

      Understood. Great job.
      Can you please provide Problem Links for every problem in SDE sheet, it is sometimes difficult to figure out the problem you are intending that should be solved by us. Thank you

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

    super explanation in the UA-cam ever searched

  • @prateeksingh7114
    @prateeksingh7114 4 роки тому +3

    One of the best explanations for this question on youtube......Thanks!!!!!

  • @parikshitrathore1510
    @parikshitrathore1510 4 роки тому +9

    Looks like first video without any dislike and 1k+ views🤩🤩

  • @amanaswal11
    @amanaswal11 4 роки тому +3

    After watching the video 4 times. Finally understood the intuition

  • @DurgaShiva7574
    @DurgaShiva7574 2 роки тому

    really explanation of intution behind algorithm force was the best thing ever.

  • @riteshkhadse4517
    @riteshkhadse4517 4 роки тому +2

    You explains every problem in the best way...

  • @mirceskiandrej
    @mirceskiandrej 2 роки тому

    This is good video that explains the problem well. It's obvious starting from 4:50. Thank you

  • @shivangisrivastava1158
    @shivangisrivastava1158 4 роки тому +9

    Really respect for you has gone to the next level, Super brilliant explanation 🔥✔️👌

    • @behindthescene4406
      @behindthescene4406 3 роки тому

      bro can u plz tell me y he said break point is the second last at 10:15

  • @abhishekmore5856
    @abhishekmore5856 2 роки тому

    I knew the algorithms for this problem but finally I know intuition also, after watching this video.

  • @amulyaabhinandan8161
    @amulyaabhinandan8161 2 роки тому

    Definitely, better than other videos...

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

    hey, @striver I request you to please use simple vocabulary for students like me. I had to watch your videos multiple times and couldn't understand them at once.

  • @paramvirramola2833
    @paramvirramola2833 4 роки тому +1

    The way you explain, even the hard problem seems easy, so i am subscribing you. Thank you

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

    Thank you very much, understood 🙂✌️

  • @kanikachauhan7391
    @kanikachauhan7391 2 роки тому

    Striver why u explained so well? Thank God you love coding. Now, helping many.

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

    Amazing Intuition and Algorithm

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

    please explain why at 2:36 even the element at 0th position also satisfies the condition of a[i]

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

      I think it should be a[i]>a[i+1]; the reason behind this is that we are traversing from backward.

  • @sugar_nutss
    @sugar_nutss 3 роки тому +3

    This is such a great explanation for such an opaque algorithm. Thank you!

  • @abhishekmore5856
    @abhishekmore5856 2 роки тому

    we can also use the binary search to reduce searching overhead.

  • @ritikashishodia675
    @ritikashishodia675 2 роки тому

    Thank u bhaiya thanks to tell intuition of this algorithm 👩‍💻😍😍😍

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

    Anyone suggest please. Even after able to solve the question should I watch these videos ?? as I have heard He explain very nicely

  • @rishabhgoyal8110
    @rishabhgoyal8110 4 роки тому +4

    Hats Off Man! Never have I ever seen this classic problem being explained in such a manner. especially the intuition! Thanks Man!

  • @Virtualexist
    @Virtualexist 3 роки тому

    Lol, finally I was able to get an approach similar to Striver sir. I came here to learn newer approach. This gives me confidence.

  • @sukritkapil9816
    @sukritkapil9816 4 роки тому +5

    Beautiful explanation and to the point. Thanks a lot!

    • @behindthescene4406
      @behindthescene4406 3 роки тому

      bro can u plz tell me y he said break point is the second last at 10:15

    • @sonusingh-zr6xw
      @sonusingh-zr6xw 3 роки тому

      @@behindthescene4406 Because the last index will be in increasing order. Break point can be at second last index or third last index or fourth last index and so on.....

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

    You are awersome. good job.

  • @ayeshasumaiya8280
    @ayeshasumaiya8280 3 роки тому +1

    Such amazing explaination. I had read articles and thought that this is a very difficult problem. But this intuition and the explanation made easy. Thank you so much!!!!!

  • @abhishekvishwakarma9045
    @abhishekvishwakarma9045 4 роки тому +1

    Every time I visit your videos I got some nice learning Thank you striver🔥👌

  • @aayushrastogi6803
    @aayushrastogi6803 4 роки тому +2

    U are doing great work Sir. The way you explain questions helps me a lot to understand and build up logic.

    • @takeUforward
      @takeUforward  4 роки тому +2

      Thanks bro so much !

    • @aayushrastogi6803
      @aayushrastogi6803 4 роки тому

      @@takeUforward Didn't expected to get a reply. Welcome Sir

    • @SiddharthaPatki
      @SiddharthaPatki 4 роки тому +1

      @@takeUforward when u solved this for the very first time, were u able to devise this algo on ur own or u had to look at some resource?

  • @sanjaykumarnayak5194
    @sanjaykumarnayak5194 2 роки тому

    Very Nice Explaination

  • @ShivamKumar-qk3vd
    @ShivamKumar-qk3vd 2 роки тому

    Prabhu Charan kahan hain aapke....?? NAILED IT BRO!!!

  • @AkashKumar-lr6hc
    @AkashKumar-lr6hc Рік тому

    Thanks for the intution ! Gfg blogs are meant for rot learning these days

  • @prathamkesarkar
    @prathamkesarkar 2 роки тому

    Wow I was able to solve it on my own after I understood the intitution

  • @sharmamukul938
    @sharmamukul938 4 роки тому

    This video provides the most intuitive and easy way to solve the problem :)

  • @tusharvaish8096
    @tusharvaish8096 2 роки тому

    I can say one word ,You are awesome!

  • @cinime
    @cinime 2 роки тому

    Understood! Amazing explanation as always, thank you very much!!

  • @RahulSingh-de6tb
    @RahulSingh-de6tb 4 роки тому +1

    watched many videos of yours, but now before watching any new videos I priorly hit like!! :) bcz this channel had won my emotions in coding. great going thanks man!!

  • @AliAkbarFaiz
    @AliAkbarFaiz 2 роки тому

    hats off to your way of explanation! understood :)

  • @mansigoyal4796
    @mansigoyal4796 4 роки тому +1

    You explained it so well. Understood it after listening once.

  • @abhigyannayak4151
    @abhigyannayak4151 3 роки тому

    What if there are duplicates which are greater than your pivot.?
    Which one will you choose?
    starting one or last one?
    and why?
    Consider this case: [2,3,1,3,3]
    answer will come by choosing the right one..
    but why?

  • @Non-residential_villager
    @Non-residential_villager 4 роки тому

    Jhakas !! kya explain kiye striver bhaiya !!

  • @shubhashisjena7915
    @shubhashisjena7915 4 роки тому +1

    BHai ur hardWork and dedication to teach us gives me a lot of hope To Study Hard ... thankU 👍

  • @dauleshgodbole6412
    @dauleshgodbole6412 3 роки тому

    so if array is 1,2,4,3,5
    id1=1
    traversing from right
    id2=4
    swapping 1,5,4,3,2
    reversing from id1+1 =>1,5,2,3,4
    which is wrong
    o/p->1,2,4,5,3
    .
    .
    .
    .
    traversing from right find the breaking point say id1
    find next greater element from id1+1 to len(arr)-1 say id2
    swap id1,id2
    reverse from id1+1 to len(arr)-1

  • @manvibhardwaj725
    @manvibhardwaj725 2 роки тому

    Thank you Striver

  • @Weirdvloggertrue
    @Weirdvloggertrue 2 роки тому

    Bhai aag laga di ladke ne

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

    Hello!
    I guess the complexity should be O(nlogn) as we are reversing the array.

  • @rohansinha2760
    @rohansinha2760 3 роки тому

    G.O.A.T explanation for this prob!!! 🐐

  • @nileshsinha7869
    @nileshsinha7869 3 роки тому

    understood ..Top notch as always

  • @sudarshanhon5539
    @sudarshanhon5539 4 роки тому

    I did this question today ....what an intuition Bhaiyya...really great explanation😊😊🙏🙏

  • @youngshahrukhkhan8179
    @youngshahrukhkhan8179 3 роки тому

    Very Nice Explanation........Keep making videos

  • @NoName-ip4tt
    @NoName-ip4tt 2 роки тому

    That is the solution I am looking for, Thnx!

  • @anupamtekale8753
    @anupamtekale8753 2 роки тому

    Brilliantttttttt Explanationn!! Loving this series!!!

  • @parambharti7095
    @parambharti7095 3 роки тому +1

    Great explanation.

  • @shubhigupta5689
    @shubhigupta5689 3 роки тому

    Your explanation is best 🔥

  • @AMAN-hc4ks
    @AMAN-hc4ks 2 роки тому +2

    instead of using second loop (to the just greater value ).can we use upper_bound stl ??

  • @ankitdubey9310
    @ankitdubey9310 3 роки тому

    solving the DsA 450 , this is the best one you explained so far

  • @So-xc3kn
    @So-xc3kn Рік тому

    Thank you strver bhai

  • @SameerKumar-sy5zb
    @SameerKumar-sy5zb 4 роки тому

    Best explanation available on UA-cam for this problem statement.Great work sir..

  • @navinkachhela7171
    @navinkachhela7171 3 роки тому

    Thanks for such a clear explanation

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

    Thank you sir

  • @codingachinilgtifirbhikrrh9009
    @codingachinilgtifirbhikrrh9009 2 роки тому

    once i get job ill join ur channel for sure

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

    Best explanation!!

  • @Virus-ke8xj
    @Virus-ke8xj 3 роки тому

    Excellent!!!!!!!!!!!!!!!!!!!!
    No words man

  • @vishakhas1867
    @vishakhas1867 2 роки тому

    Just amazing. Really respect you sir.. Hats off to your hard work!

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

    jod❤‍🔥 thank you striver for this much good explanation

  • @kumararab758
    @kumararab758 4 роки тому

    easiest explanation. Thanks a lot man

  • @kunalroy1026
    @kunalroy1026 3 роки тому +1

    This is next level explanation❤❤💥💥

  • @santanupatra2800
    @santanupatra2800 4 роки тому +1

    Nice explaination. You made it very easy to understand 🔥

  • @aman-gy5nn
    @aman-gy5nn 3 роки тому

    @striver 1 3 5 2 4 is not increasing from both backward and forward

  • @akshatkumar1321
    @akshatkumar1321 4 роки тому +1

    Sir ,nice to have such videos , please keep this placement series going.

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

    Superb explanation❤

  • @riyakushwaha8429
    @riyakushwaha8429 3 роки тому

    Hii, Your way of explaning is really good. Could you please make a video on smallest sufficient team leetcode problem.

  • @bhaveshkumar6842
    @bhaveshkumar6842 3 роки тому

    Broooo! You're the best! 😍

  • @sharanpreetchadha3579
    @sharanpreetchadha3579 3 роки тому +1

    This is just a beautiful question and an amazing explanation

  • @madhurimakalivarapu9610
    @madhurimakalivarapu9610 4 роки тому

    ur just fab bhaya. never stop .

  • @thecodegod3852
    @thecodegod3852 2 роки тому

    Thanks a lot Striver for such a beautiful explanation!!

  • @muskanjhamani4766
    @muskanjhamani4766 2 роки тому

    Such a nice Explanation😃

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

    love you so much striver bhaiya

  • @TheElevatedGuy
    @TheElevatedGuy 2 роки тому

    Good intuiton explanation.

  • @mansoorshakir5539
    @mansoorshakir5539 3 роки тому

    Mind blowing explanation 🤯🤯. Thanks striver ❤

  • @SachinVerma-td8ou
    @SachinVerma-td8ou 4 роки тому +1

    A very much thank you 🥰

  • @maulikdev5040
    @maulikdev5040 2 роки тому

    what an amazing explanation!!