Permutations 2 (LeetCode 47) | Full solution with backtracking examples | Study Algorithms

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024

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

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

    Thank you so much! What a in-depth explanation !

  • @LeelaLakshmiKundi
    @LeelaLakshmiKundi 9 หลายเดือนก่อน +1

    Good explanation...Cleared my doubt🥰🥰

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

      Keep watching

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

    Thanks

  • @AmiteshAnand-ow4hn
    @AmiteshAnand-ow4hn 3 หลายเดือนก่อน +1

    for(int i = 0; i < nums.length; i++){
    if(used[i] || i > 0 && nums[i] == nums[i-1] && !used[i - 1]) continue;
    used[i] = true;
    tempList.add(nums[i]);
    backtrack(list, tempList, nums, used);
    used[i] = false;
    tempList.remove(tempList.size() - 1);
    }
    This will be better optimization

    • @TON-108
      @TON-108 3 หลายเดือนก่อน +1

      Right! If we find again in base case, it will add extra head of O(n).
      As our array is already sorted its better to use your mentioned approach 💯

  • @ImranKhan-ne3cj
    @ImranKhan-ne3cj ปีที่แล้ว

    great man appreciate your work !

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

    Thank you brother

  • @subee128
    @subee128 8 หลายเดือนก่อน +1

    Thank you

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

    You are anyway checking for the condition that if the obtained list is already contained in the results so it'll work without the used array condition too right?....i understand some function calls will be prevented with it's use but it'll still work without it right?

  • @user-oc7dv7xn9l
    @user-oc7dv7xn9l 3 หลายเดือนก่อน

    U are amazing! However, could u explain why did we need to sort array?

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

      So that you are covering all similar cases. You can have two digits that are same, if they are all grouped together, they can be removed as duplicates

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

    There is some issue with ur mic or voice

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

    in recursive call where you are passing nums not the { I,L,Y} how it works

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

    Awsm

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

    if we have an int[] = {1,1,2,5} as an ex, the first iteration for the for loop within the backtrack method it will skip the first if statement since used[i] will be false.
    then we set the used[i] = true then add the element to tempList.
    then we backtrack then set used[i] = false then remove the element from the tempList.
    my question is for the second iteration for the loop, used[i] will still be false but our intention is to simply skip right? how and when will it ever hit the first if statement for when used[i] = true?

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

      btw i came here from watching your video on permutations 1 and i love your explanations. you got yourself a subscriber🔥

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

      if its not much trouble, do you mind answering my above question?

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

      i think I am not understanding your question correctly... can you explain with a simpler example? I can try to help.

  • @user-hb5xr8sj1u
    @user-hb5xr8sj1u 7 หลายเดือนก่อน

    thanku sir

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

    general combinatorial search pe ek video banao :)

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

      Glad to hear from you old friend :)

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

    if we are already checking if the resultList contains tempList of not then why to use this 'used' array. 😒

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

      can you please clarify your question with an example? I am unable to follow

    • @mohamedhamshakothars4238
      @mohamedhamshakothars4238 4 วันที่ผ่านมา

      We can use sending the start index as parameter to the recursive call like you did in permutation 1 video instead of using a used array why using this array which has more space complexity

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

    In leetcode it is giving 909 ms