Leetcode - Combination Sum (Python)

  Рет қаралды 13,022

Timothy H Chang

Timothy H Chang

Күн бұрын

Пікірлер: 26
@northridgefield
@northridgefield Жыл бұрын
1) For non-Python people, "range" is inclusive on start but exclusive on right. It can be misleading as in Kotlin we use 1..target that is inclusive on both ends. 2) Big O: according to chatGPT+ it's hard to be precise about space complexity as it depends on nature of the input, it settled at: O(target × 2^candidates.length). In terms of time complexity: O(n × target × 2^candidates.length). Anyone thinks there's better Big O explanation - leave a comment :) Very cool explanation Tim, thanks.
@ritteshpv2196
@ritteshpv2196 2 жыл бұрын
All your videos are just awesome with best and simple explanation. Also, it would be really great if you could explain explain the Time Complexity and space complexity as well. This is the only extra requirement that every one of your subscriber is wanting from you, please update in description atleast
@anaken127
@anaken127 7 ай бұрын
it is match more convinient and faster then the recursion way, thanks!
@DiaaHaresYusf
@DiaaHaresYusf Жыл бұрын
very thanks for this amazing video , I wanted just to mention that candidates does not have to be sorted , logically I tested and i tested by code too. thanks bro
@darshakmehta
@darshakmehta 2 жыл бұрын
your videos are always awesome sir. besides, extra clap for whiteboard assisted explanation!! 👏🏻👏🏻👏🏻
@RajSingh-dl2lk
@RajSingh-dl2lk 3 жыл бұрын
great solution, can you explain why is the time complexity is soo less even though there are three loops. Also can we do all the Backtracking problems using DP?
@KBLive7
@KBLive7 3 жыл бұрын
Great vid, clear explanation. Got my sub! Keep them coming!
@timc3406
@timc3406 3 жыл бұрын
Sure thing! Thank you!
@wolfwalker_
@wolfwalker_ 2 жыл бұрын
that would be great if you could explain on the whiteboard with the example given by leetcode.
@ArunNalluri
@ArunNalluri 2 жыл бұрын
great way to solve this problem! Thank you! the way you code is a little unconventional but the explanation and approach is excellent!
@yilmazbingol4838
@yilmazbingol4838 3 жыл бұрын
smart solution. How did it satisfy the uniqueness?
@OverLordOfDa3rdWorld
@OverLordOfDa3rdWorld 2 жыл бұрын
Dude, you're amazing! Thank you!!!
@greyreynyn
@greyreynyn 3 жыл бұрын
Amazing explanation! I am just curious how to decide whether a problem can be solved by DP or not? It seems unintuitive to me to try this approach. Do you have any tips on how to tell when it's worthwhile to try this approach?
@FlexGC
@FlexGC 3 жыл бұрын
If you can break up the problem into smaller subproblems. If the subproblems solved will help you get to the answer more efficently (memoization).
@greyreynyn
@greyreynyn 3 жыл бұрын
@@FlexGC That makes sense, I guess logically if 1) you think of calculating the combinations from 0 -> target, and 2) you write the combinations out and notice combinations that sum to larger values are made of parts that sum to smaller values, then the approach should follow. And by figuring out the combinations that sum to smaller values, you can use those later (thats the memo part) I guess it's not immediately obvious to me that the right thing to do is start counting all the different ways to sum to the numbers between 1 and target. Maybe I just need more exposure to these types of problems.
@Yu-pw2pp
@Yu-pw2pp 2 жыл бұрын
good videos, very helpful!
@liwensi1218
@liwensi1218 Жыл бұрын
Great video! I am new for python. I am trying to use "blist.append(c)" to replace the "blist+[c]". I got nonetype error. Why?
@liwensi1218
@liwensi1218 Жыл бұрын
Figured it out by myself. the "blist.append(c)" will add c into blist, but the return value will be none. Another thing is append will not create a new list. Here we need copy() the blist first. The below code will be same with dp[i].append(blist + [c]), temp = blist.copy() temp.append(c) dp[i].append(temp)
@BananaButcher
@BananaButcher 6 ай бұрын
@@liwensi1218 great job man. you did well
@jay-rathod-01
@jay-rathod-01 2 жыл бұрын
beautiful
@jieshi169
@jieshi169 4 жыл бұрын
Good job! Thanks for the explanation!
@timc3406
@timc3406 3 жыл бұрын
You're welcome!
@xiaoxiaoliu2018
@xiaoxiaoliu2018 2 жыл бұрын
You are best
@abhiseka5735
@abhiseka5735 4 жыл бұрын
What is time and space complexity?
@timc3406
@timc3406 4 жыл бұрын
Honestly not sure... N * N^K maybe?
@mohammedsafia5434
@mohammedsafia5434 4 жыл бұрын
@@timc3406 the RunTime is much better than both recursive DFS and Memoized solution. which is 2^n exponential time. Space complexity also almost the same if we take into account the recursion stack storage as well. I think the run time in the worst case for your approach will be N^3. ie. N^2 for moving through 2D DP Table and N for each cell to find all the pair.
Combination Sum - Backtracking - Leetcode 39 - Python
15:10
NeetCode
Рет қаралды 326 М.
Dynamic Programming Explained (Practical Examples)
29:00
Tech With Tim
Рет қаралды 108 М.
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
Leetcode - Combination Sum (Python) (revisited)
8:09
Timothy H Chang
Рет қаралды 3,8 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
House Robber
7:32
Kevin Naughton Jr.
Рет қаралды 85 М.
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 19 М.
Leetcode - Course Schedule (Python)
9:47
Timothy H Chang
Рет қаралды 10 М.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 740 М.
LeetCode 39 - Combination Sum
20:28
Time Complexity Infinity
Рет қаралды 14 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН