I was struggling with backtracking concept of this problem but your explanation is so easy to understand! Thank you
@KnowledgeCenter2 жыл бұрын
Glad to hear.
@siddharthsingh43304 жыл бұрын
It was hard to understand but code made it all easy. Thank you Sir
@rohithbharathi366422 күн бұрын
just adding this if len(combination) > k: return which is missing in the python solution saves a hell lot of time
@NatureLover-oq6uc2 жыл бұрын
VERY VERY GOOD EXPLANATION SIR....
@KnowledgeCenter2 жыл бұрын
Thanks for liking
@stith_pragya Жыл бұрын
Thank You So Much Brother...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@KnowledgeCenter Жыл бұрын
Glad you liked the video.
@rajeshg17374 жыл бұрын
Hacky (Python): def combinationSum3(self, k: int, n: int) -> List[List[int]]: ans = [] numbers = [i for i in range(1,10) ] for combination in itertools.combinations(numbers, k): if sum(combination) == n: ans.append(list(combination)) return ans
@pif50239 ай бұрын
Thank you for the video! I got it correct evaluating all permutation but LeetCode was not happy with the time complexity. Restarting the loop from the last number evaluated does force the loop to only evaluate combinations and only once. That was something I wasn't sure of.
@ankoor4 жыл бұрын
Python using recursion: def combinationSum3(self, k, n): def combination(A, k, n, output, result): if len(A) == 0: if len(result) == k and sum(result) == n: output.append(result) return L = result + [A[0]] R = result A = A[1:] combination(A, k, n, output, L) combination(A, k, n, output, R) A = [1, 2, 3, 4, 5, 6, 7, 8, 9] result = [] output = [] combination(A, k, n, output, result) return output
@Vijaysharma-nz8fi4 жыл бұрын
Thanks a lot for nice explanation. Sir could you please explain lete code problem#282 Expression add operators. Thanks.
@devbhattacharya1532 жыл бұрын
Thanks a lot sir
@KnowledgeCenter2 жыл бұрын
Welcome.
@janmichaelaustria6204 жыл бұрын
thank you once again sir! your videos have a good balance of theory and implementation!
@chloe33373 жыл бұрын
hello i don't understand how the numbers will be popped off the list twice once the first combination has been found. From temp = [1,2,6] -> temp.pop() -> [1,2] and then 2 pops out again and it becomes [1]
@paragroy53593 жыл бұрын
Nice explanation sir.......
@sainikhilpalukuri13734 жыл бұрын
Sir, I think the time complexity is o(n3) sir because we are looking all the combinations. Sir please correct me if I am wrong
@KnowledgeCenter4 жыл бұрын
You are assuming k = 3, it was just in example. K can be any value from 1 to 9. e.g., if k = 2, we just need 2 values. If k = 5 we need to find 5 values.
@midhileshmomidi24344 жыл бұрын
Sir I have two doubts 1)Why did you take combination.copy() instead of combination 2)In recursion even after the sum exceeds like for sum = 9 combination is 2,3,4 then function is calling for 2,3,5.. 2,3,6 How to stop these calls Please explain
@midhileshmomidi24344 жыл бұрын
I did with itertools as that was the first idea pop up in mind But while trying in the backtracking approach I struggled to write recursive call function How to improve writing recursive functions please help sir