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?
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?
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
Thank you so much! What a in-depth explanation !
Good explanation...Cleared my doubt🥰🥰
Keep watching
Thanks
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
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 💯
great man appreciate your work !
Thank you brother
Thank you
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?
U are amazing! However, could u explain why did we need to sort array?
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
There is some issue with ur mic or voice
in recursive call where you are passing nums not the { I,L,Y} how it works
Awsm
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?
btw i came here from watching your video on permutations 1 and i love your explanations. you got yourself a subscriber🔥
if its not much trouble, do you mind answering my above question?
i think I am not understanding your question correctly... can you explain with a simpler example? I can try to help.
thanku sir
general combinatorial search pe ek video banao :)
Glad to hear from you old friend :)
if we are already checking if the resultList contains tempList of not then why to use this 'used' array. 😒
can you please clarify your question with an example? I am unable to follow
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
In leetcode it is giving 909 ms