Combination Sum iii | LeetCode 216 | C++, Java, Python

  Рет қаралды 11,584

Knowledge Center

Knowledge Center

Күн бұрын

Пікірлер: 23
@MiteshTank1
@MiteshTank1 2 жыл бұрын
I was struggling with backtracking concept of this problem but your explanation is so easy to understand! Thank you
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Glad to hear.
@siddharthsingh4330
@siddharthsingh4330 4 жыл бұрын
It was hard to understand but code made it all easy. Thank you Sir
@rohithbharathi3664
@rohithbharathi3664 22 күн бұрын
just adding this if len(combination) > k: return which is missing in the python solution saves a hell lot of time
@NatureLover-oq6uc
@NatureLover-oq6uc 2 жыл бұрын
VERY VERY GOOD EXPLANATION SIR....
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Thanks for liking
@stith_pragya
@stith_pragya Жыл бұрын
Thank You So Much Brother...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@KnowledgeCenter
@KnowledgeCenter Жыл бұрын
Glad you liked the video.
@rajeshg1737
@rajeshg1737 4 жыл бұрын
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
@pif5023
@pif5023 9 ай бұрын
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.
@ankoor
@ankoor 4 жыл бұрын
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-nz8fi
@Vijaysharma-nz8fi 4 жыл бұрын
Thanks a lot for nice explanation. Sir could you please explain lete code problem#282 Expression add operators. Thanks.
@devbhattacharya153
@devbhattacharya153 2 жыл бұрын
Thanks a lot sir
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Welcome.
@janmichaelaustria620
@janmichaelaustria620 4 жыл бұрын
thank you once again sir! your videos have a good balance of theory and implementation!
@chloe3337
@chloe3337 3 жыл бұрын
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]
@paragroy5359
@paragroy5359 3 жыл бұрын
Nice explanation sir.......
@sainikhilpalukuri1373
@sainikhilpalukuri1373 4 жыл бұрын
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
@KnowledgeCenter
@KnowledgeCenter 4 жыл бұрын
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.
@midhileshmomidi2434
@midhileshmomidi2434 4 жыл бұрын
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
@midhileshmomidi2434
@midhileshmomidi2434 4 жыл бұрын
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
@annesyabanerjee1892
@annesyabanerjee1892 4 жыл бұрын
which software you are using ??
House Robber | LeetCode 198 | C++, Java, Python
18:45
Knowledge Center
Рет қаралды 11 М.
Combination Sum - Backtracking - Leetcode 39 - Python
15:10
NeetCode
Рет қаралды 327 М.
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 39 МЛН
Path Sum III | LeetCode 437 | Medium
25:01
Code And Coffee
Рет қаралды 14 М.
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 10 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 675 М.
Leetcode - Combination Sum III (Python)
7:15
Timothy H Chang
Рет қаралды 2,1 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 445 М.
Permutations - Leetcode 46 - Recursive Backtracking (Python)
9:42
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 700 М.
Combination Sum Problem #Backtracking
16:40
Code with Alisha
Рет қаралды 21 М.