Leetcode 46. Permutations : Introduction to backtracking

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024

ความคิดเห็น • 111

  • @ComputerBread
    @ComputerBread  ปีที่แล้ว +15

    Hey! I am back!
    Thank you so much for the support! It is truly motivating.
    I am coming back with more videos, for now I am shifting my focus on JavaScript, but if you want me to cover anything, let me know 😀
    My new video about JavaScript Objects: th-cam.com/video/TFQQ-H5foZs/w-d-xo.html

    • @alitaha1200
      @alitaha1200 6 หลายเดือนก่อน +1

      Please do more backtracking videos, more leetcode kind of videos. The demand for this is huge.

    • @ComputerBread
      @ComputerBread  6 หลายเดือนก่อน

      @@alitaha1200 Sure, do you have a specific leetcode question in mind, or anything specific you would like me to talk about?

  • @rohinirenduchintala
    @rohinirenduchintala ปีที่แล้ว +31

    This is the best backtracking video i have seen. Thank you for saving me another 24 hours of effort into learning this and saving me the rest of my hair on the head from being pulled!

  • @sontredis2579
    @sontredis2579 ปีที่แล้ว +12

    props to you. This video was the literal ONLY video that helped me understand backtracking and how to apply the concept to ANY problem

  • @samjackson4982
    @samjackson4982 ปีที่แล้ว +7

    "No one asked your opinion" - I laughed hard bro.. You are too mean. 😅🤣

  • @denysostapenko445
    @denysostapenko445 2 ปีที่แล้ว +15

    Wow! Your way to present materials is slightly unusual, but man! I've just seen one of the clearest explanations of backtracking and the permutation problem. Tree visualization was super helpful. Definitely got my like. Make more content!

  • @mrboyban
    @mrboyban 2 ปีที่แล้ว +6

    1:10😂😂😂😂😂 , just made stay on this video. I like that reality check style!Good stuff mate.

  • @vcb007
    @vcb007 ปีที่แล้ว +4

    This is the best video to start of solving a backtracking. Now I can think of optimisations, all the solutions I saw were swapping indexes but didn't seem intuitive although it's understandable. Your video is to the point and intuitive as well. Thanks

  • @ricky7389
    @ricky7389 10 หลายเดือนก่อน +2

    This is the cleanest backtracking explanation I've ever seen.

  • @oleksandrshestopal5749
    @oleksandrshestopal5749 3 ปีที่แล้ว +12

    The best explanation I have seen so far!!! Please do more videos

  • @erana4124
    @erana4124 2 ปีที่แล้ว +3

    Great explanation 🙂
    "Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime"
    Here you explained the background knowledge behind the algorithm, and not just explaining the solution flow 🙂that's how teaching should be done
    Kudos 😀

  • @ashishm
    @ashishm 2 ปีที่แล้ว +4

    Superb explanation. I was trying to come up with the recipe for backtracking and came across this video. Really helpful.

  • @TejaDuggirala
    @TejaDuggirala 2 ปีที่แล้ว +2

    Wow.. this is the simplest permutation solution I have seen. Everyone doing that swapping thing which is so confusing. Thanks.

  • @user-gp8fr1nd3w
    @user-gp8fr1nd3w 2 ปีที่แล้ว +7

    I really loved this! Please continue this series.

  • @rameshreddibathuni
    @rameshreddibathuni 3 ปีที่แล้ว +4

    The best among all the videos I watched related to this problem !!

  • @christianjt7018
    @christianjt7018 หลายเดือนก่อน

    The backtracking recipe is pure golden, this is a superb explanation, thank you.

  • @chandanabhatt8231
    @chandanabhatt8231 ปีที่แล้ว +3

    I really like how provided backtracking recipe .

  • @shubhamkamdi6606
    @shubhamkamdi6606 2 ปีที่แล้ว +4

    You made backtracking super easy to understand!

  • @CSDex
    @CSDex 9 หลายเดือนก่อน

    Seemed like you got nervous when you whipped out the code haha, I feel that. Best backtracking video I’ve watched so far. You did a great job of simplifying Back To Back SWE’s videos. Adding that backtracking recipe and using it to work through the problem was great.

  • @dareTake
    @dareTake 2 ปีที่แล้ว +3

    Thanks, this was very helpful compared to other solutions that I had encountered. My initial thought process was to use a set and do a difference between the original set and permutation, didn't think of using a simple boolean array.

  • @rednationsox2802
    @rednationsox2802 3 ปีที่แล้ว +3

    best videos for backtracking ever. Hoping more explaination videos

  • @stoup8778
    @stoup8778 หลายเดือนก่อน

    I really like your soln, very clear explanation. I didnt think of using a seperate vector to keep track of used elements either - I tried to used a set when I was implementing on my own and failed miserably haha

  • @fufuto
    @fufuto 2 ปีที่แล้ว +1

    Why do we need to 'undo the choice' after permutation? We already discovered the permutations and print them. Why should I reverse back to original?

  • @harsh9028
    @harsh9028 ปีที่แล้ว +2

    Good explanation but would have liked it more if you also explained a full recursive run down of your code.

  • @soanonso
    @soanonso 2 ปีที่แล้ว +3

    Excellent explanation. Thank you!

  • @hoangvu-zu6qg
    @hoangvu-zu6qg 3 หลายเดือนก่อน

    Really thanks to you, guy. This video made me more understand about backtracking.

  • @JMac___
    @JMac___ 5 หลายเดือนก่อน

    i love you man, this made a lot of sense to me and your backtracking building block helped me come to 90% of solution on my own

  • @bonginscandinavia
    @bonginscandinavia 7 หลายเดือนก่อน

    Nice explanation for the letter A. I just paused and laughed out loud a while before moving on. 😄

  • @slizverg23
    @slizverg23 ปีที่แล้ว +1

    Dude, thank you sooo much for your solution! I'd almost gave up on this problem but you explanation was realy clean! ))

  • @NirmalSilwal
    @NirmalSilwal 3 ปีที่แล้ว +5

    haha I like your style

  • @pranjansana2598
    @pranjansana2598 3 ปีที่แล้ว +4

    This is Badass,bro!!

  • @MisterCK124
    @MisterCK124 ปีที่แล้ว +1

    Thanks, good explanation!

  • @darshandani1
    @darshandani1 4 หลายเดือนก่อน

    Thanks for this. Great explanation !

  • @mariushostinar663
    @mariushostinar663 ปีที่แล้ว +3

    The beginning of the video was so cringe

  • @desipawal
    @desipawal ปีที่แล้ว +2

    beautifully explained

  • @YOLITOPINTO
    @YOLITOPINTO 3 ปีที่แล้ว +2

    Noice explanation, I liked the graphics.

  • @nerdy8644
    @nerdy8644 ปีที่แล้ว +14

    You kinda sound like jar jar binks

  • @motngay1niemvui
    @motngay1niemvui 2 ปีที่แล้ว +1

    Sir, please comeback, this is the only one video that i understand -.-

  • @10xDevLog
    @10xDevLog หลายเดือนก่อน

    Great video! Thanks for this

  • @xit
    @xit 9 หลายเดือนก่อน

    Interviewer: do this problem1;
    ComputerBread: I'm the one doing it, I'll do problemA; OK!
    ...interviewer leaves the call

  • @BobBob-e
    @BobBob-e ปีที่แล้ว

    to me it seems like the return in the first if statement is unnecessary since if the goal is reached none of the choices will be valid and the recursion will stop?

    • @ComputerBread
      @ComputerBread  ปีที่แล้ว +1

      In this case, yes, but returning early avoids unnecessary computation.

  • @deepakreddy6528
    @deepakreddy6528 ปีที่แล้ว +1

    For anyone who wants a more intuitive solution the probem, by simply picking all choices 1 by 1 and also discarding the appended characters to allow for all permutations.
    class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
    res = []
    visited = [False for _ in range(len(nums))]
    def dfs(subset):
    if len(subset) == len(nums):
    res.append(subset.copy())
    return
    for i in range(len(nums)):
    if not visited[i]:
    #Pick the choice
    visited[i] = True
    subset.append(nums[i])
    dfs(subset)
    #Undo the choice
    visited[i] = False
    subset.pop()
    dfs([])
    return res

  • @sarwarjahan05
    @sarwarjahan05 2 ปีที่แล้ว +1

    A very good content 👌

  • @dennisllopis2478
    @dennisllopis2478 ปีที่แล้ว

    2:26 lmao… I was concerned for a moment 😅

  • @Arvindh-xp1lt
    @Arvindh-xp1lt 3 ปีที่แล้ว +1

    great looking for more videos

  • @pratikawate5826
    @pratikawate5826 3 ปีที่แล้ว +1

    Do more videos..it's been 1 year no more videos.. 🙄

  • @regulardev
    @regulardev ปีที่แล้ว +1

    Thank a lot. It was really helpful in understanding both backtracking and permutation. Future viewers, this is O(n^n ), e.g for an array lof length 3, this logic is iteratively equivalent to
    int len = arr.Length;
    for(int i=0; i < len; i++) {
    for(int j=0; j < len; j++) {
    for(int k=0; k < len; k++) {
    if(i != j && j != k && i != k) {
    List perm = new() {arr[i], arr[j], arr[k] };
    result.Add(perm);
    }
    }
    }
    }

  • @karmeshduggar6694
    @karmeshduggar6694 2 ปีที่แล้ว +1

    Thank you so much sir!

  • @gazoonman
    @gazoonman 2 ปีที่แล้ว +2

    A is a number
    change my mind

  • @chaunguyen8202
    @chaunguyen8202 3 ปีที่แล้ว +1

    Much better than swapping

  • @tuano-wp9du
    @tuano-wp9du 9 หลายเดือนก่อน

    very nice !! thank you very much

  • @aadi7448
    @aadi7448 ปีที่แล้ว +1

    All the backtracking stuff is okay, but when are the joke videos coming? 😝
    Jk, thanks a lot, this is such a clean explanation!

  • @CodingWerkstatt
    @CodingWerkstatt ปีที่แล้ว

    starts bad but is actually insanely good.

  • @weezarrdd
    @weezarrdd ปีที่แล้ว

    hey where are you from? your accent is super cool

    • @ComputerBread
      @ComputerBread  ปีที่แล้ว +1

      Thank you, I am from France, but I try to "minimize" my accent.

  • @gurjotkheeva130
    @gurjotkheeva130 8 หลายเดือนก่อน

    THE BACKTRACKING RECIPE IS PURE GOLD! .... see @4:08

  • @shaileshwaghmare3
    @shaileshwaghmare3 3 ปีที่แล้ว +1

    Nicely explained

  • @notdumb3182
    @notdumb3182 2 ปีที่แล้ว +1

    I love you bro.

  • @snpro_007
    @snpro_007 2 ปีที่แล้ว +1

    Very helpful , thanks!!!!!!!!

  • @adam23sp
    @adam23sp 2 ปีที่แล้ว +1

    amazing

  • @piyushrewatkar6825
    @piyushrewatkar6825 ปีที่แล้ว +1

    best solution!

  • @vikramragunathan6392
    @vikramragunathan6392 2 ปีที่แล้ว +1

    Dope :)

  • @Yarin5879
    @Yarin5879 2 หลายเดือนก่อน

    thank you so much

  • @muratogulcan34
    @muratogulcan34 11 หลายเดือนก่อน

    But A is not a number

  • @supremoluminary
    @supremoluminary ปีที่แล้ว +1

    I don’t mind the jokes, but actually, they’re kind of a distraction. I’m trying to understand this.
    Unfortunately, you lost me on the coding.

  • @minhbui4817
    @minhbui4817 2 ปีที่แล้ว

    Neetcode has nothing on u lol

  • @caminante4222
    @caminante4222 3 ปีที่แล้ว +27

    Good content but too much joking and nonsense

    • @xSlimLizardx
      @xSlimLizardx 2 ปีที่แล้ว +12

      dont be boring

    • @mostinho7
      @mostinho7 2 ปีที่แล้ว +24

      Wow…the guy makes a great video and u complain about him being funny

    • @ssuriset
      @ssuriset 2 หลายเดือนก่อน

      Oh god here we go

    • @Tlj10144
      @Tlj10144 หลายเดือนก่อน

      You must be fun at parties

  • @bauyrjanjyenis3045
    @bauyrjanjyenis3045 2 ปีที่แล้ว +2

    Terrible explanation!

  • @thoniasenna2330
    @thoniasenna2330 13 วันที่ผ่านมา +1

    hahahah i love you! best regards from brazil!

  • @NYBlueBlueSky
    @NYBlueBlueSky ปีที่แล้ว +2

    it's a good video!

  • @richardnorth1881
    @richardnorth1881 3 ปีที่แล้ว +6

    Excellent quality- you have a talent for teaching

  • @samkomo4289
    @samkomo4289 2 ปีที่แล้ว +3

    Thank you so much! The recipe and the ‘used’ trick really helped me understand

  • @luckyim6504
    @luckyim6504 2 ปีที่แล้ว +2

    This is legendary...backtracking receipe....omggg this video is so so so helpful!!

  • @noodkhannavin
    @noodkhannavin ปีที่แล้ว +1

    A is not number .. 😅😂

  • @dubanrubiano84
    @dubanrubiano84 ปีที่แล้ว +1

    jsjsjs 1:15

  • @Joytokey1231
    @Joytokey1231 ปีที่แล้ว +2

    Hey! The video is a great introduction to the topic, but I'm afraid you're presenting it to be more trivial than it really is, which may lead some viewers to feel they understand it when they might not. If possible, breaking down the algorithm step by step and explaining each recursive call in detail (at least until the second permutation is generated) could help. The recursive calls that produce nested loops and even more recursive calls aren't simple to keep track of in your head, especially since the "undoing" at the end of the initial for loop only happens after all those nested recursions occur and call their own removals.
    If you do so, keeping track of which indexes are used in your "used" array instead of the actual numbers may add complexity to the process of explaining it, thanks!

    • @FabriGLiza
      @FabriGLiza 8 หลายเดือนก่อน

      Can you please explain to me how the hell does the algorithm manages to not take the previous vector and generate another one totally different? I'm having a rough time figuring it out. If the first vector was [1, 2, 3] and then deletes every element until the vector is void (and every element of the bool vector is false again), why in the world would the algorithm pick 3 after 1, instead of 2? :(

  • @paulcardoos6277
    @paulcardoos6277 3 ปีที่แล้ว +4

    Thank you for this great video.

  • @tolska.
    @tolska. 10 หลายเดือนก่อน +1

    everything was cool until 8:18 ,you became a terrorist

    • @ComputerBread
      @ComputerBread  10 หลายเดือนก่อน

      yeah, I was so done with it! Sorry

    • @tolska.
      @tolska. 10 หลายเดือนก่อน

      @@ComputerBread hahahahahaha

  • @ishanpatel8683
    @ishanpatel8683 ปีที่แล้ว +1

    That backtracking recipe is goated

  • @enoch8835
    @enoch8835 ปีที่แล้ว +1

    OK JUST READ THE CODE
    but for real thank u for this video

  • @OverLordOfDa3rdWorld
    @OverLordOfDa3rdWorld 2 ปีที่แล้ว +1

    BRO!!! YOU TAUGHT ME BACKTRACKING HOLY SHHHHHHHHIIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEET!!!!!!!!!!

  • @tranpaul4550
    @tranpaul4550 5 หลายเดือนก่อน

    Oh my God, It just clicked, all the time studying backtracking pattern

  • @hawadrammeh8870
    @hawadrammeh8870 2 ปีที่แล้ว +1

    I love you and your ascii joke lol

  • @Dev-zr8si
    @Dev-zr8si 2 ปีที่แล้ว +1

    This is great I hope you make more.

  • @historyrevealed01
    @historyrevealed01 7 หลายเดือนก่อน

    very nice, thanks

  • @robertkovac7824
    @robertkovac7824 2 หลายเดือนก่อน

    thanks

  • @Ziggy0120
    @Ziggy0120 3 ปีที่แล้ว +1

    1:00 hahaha

  • @emanuelrollin2930
    @emanuelrollin2930 5 หลายเดือนก่อน

    less comedy please 😭

    • @ComputerBread
      @ComputerBread  5 หลายเดือนก่อน

      Ok, no fun allowed, I am sorry

  • @Tlj10144
    @Tlj10144 หลายเดือนก่อน

    What's up with the 188 dislikes lol

    • @ComputerBread
      @ComputerBread  หลายเดือนก่อน

      it's 191 now T_T

    • @Tlj10144
      @Tlj10144 หลายเดือนก่อน

      @@ComputerBread fuck them, you should do more videos like this

  • @peregrine17
    @peregrine17 ปีที่แล้ว

    you could have explained it with a dry run of the code

  • @deepak1725
    @deepak1725 2 ปีที่แล้ว

    Nobody asked my opinion 🤣