LEETCODE 46 (JAVASCRIPT) | PERMUTATIONS I

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • Hey everyone. Check out this in-depth solution for leetcode 46.

Комментарии • 29

  • @PavelS54
    @PavelS54 2 года назад +9

    Dude, this is one of those mind-blowing situations where I struggled for hours and you explained it in 15 minutes. Thanks very much. You helped a lot.

  • @techchains4428
    @techchains4428 2 года назад +10

    For those unfamiliar w/ the swapping syntax:
    for(var j = i; j < nums.length; j++) {
    // swap the positions
    var temp = nums[i];
    nums[i] = nums[j];
    nums[j] = temp;
    dfs(i + 1, nums);
    // unswap the positions as we go back up the tree
    nums[j] = nums[i];
    nums[i] = temp;
    }

  • @xXThUmPerRXx
    @xXThUmPerRXx 2 года назад +1

    I've spent hours trying to figure out this problem. I watched your video once, and immediately understood it with your tree. Great work!!

  • @lucasgao5505
    @lucasgao5505 3 года назад +17

    In the tree first swap why swap 1,2,3 to 3,1,2 not 3,2,1 ?

  • @vivienpmc
    @vivienpmc Год назад

    This helped me understand recursive backtracking a lot. Thanks a lot!

  • @joonpak
    @joonpak 2 года назад +2

    Interesting… this isn’t how I solved this at all (although I too used recursion) 🤯 Amazing how many different ways there are to solve a challenge!

  • @isaaca.8731
    @isaaca.8731 2 года назад

    great explanation, the visual in the beginning helped alot, got my interview on monday hope I pass

  • @user-nj3lg7wi5r
    @user-nj3lg7wi5r Год назад

    Thank you very much. I should have thought of that earlier.

  • @RicardoBuquet
    @RicardoBuquet 2 года назад

    Andy I really appreciate your playlist, you are amazing!

  • @rimzb
    @rimzb 2 года назад +1

    Thank you, Andy!

  • @fufuto
    @fufuto 2 года назад

    In backtracking, why do we have to re-swap? we already have the answers by looking at the leaf

  • @abdulgaffarabdulmalik4333
    @abdulgaffarabdulmalik4333 2 года назад +1

    Nice solution, thanks!
    I got confused initially, about why you swapped twice😀
    But, I think it would be okay to avoid mutating the original nums array.
    e.g
    for(let j=i; j< nums.length; j++){
    let temp = [...nums];
    [temp[i], temp[j]] = [temp[j], temp[i]];
    dfs(i+1, temp);
    }
    JS can be tricky at times.

  • @DavidK-ex4km
    @DavidK-ex4km Год назад

    Hey Andy, I'm not understanding line 21. Why do we need the swap again??

  • @LPnotes
    @LPnotes 2 года назад

    Thanks so much for this backtracking/recursion series!

  • @ritikbhatt2986
    @ritikbhatt2986 2 года назад

    very nicely explained thankyou so much

  • @aryankali5446
    @aryankali5446 Год назад

    Dude, I am trying same logic before seeing this video. I am only push the nums as it is in result. I am not understand the reason behind the push as nums.slice(). please u see then replay please.

  • @worldwide6626
    @worldwide6626 2 года назад

    Why is it j=i and not j=0 in the for loop?

  • @jattinbadrinath
    @jattinbadrinath 2 года назад

    What does it mean when he says "when we get to the leaf node, we need to scan that" ?

    • @coolboyalan
      @coolboyalan Год назад

      we will store that copy of array in our result array.

  • @bharath_v
    @bharath_v 2 года назад

    Good One!

  • @shibmobileverse468
    @shibmobileverse468 Год назад

    What about two numbers? :( [1, 2]

  • @SuperKidontheblock
    @SuperKidontheblock Год назад

    What whiteboard is this?