|
4 | 4 | ## 78. Subsets
|
5 | 5 |
|
6 | 6 | 1. Intuition: Need to find all possible subset (super-set/the power set), backtracking
|
7 |
| -2. Choice : all the numbers in the unique array |
8 |
| -3. Choose : one element at a time (this can be done by in recursive call by current choice index + 1 ) |
9 |
| -4. Explore : recursive cal on above choose and next choice |
10 |
| -5. Un-choose : remove the chosen element |
11 |
| -6. Explore : recursive cal on above un-choose and the next choice |
| 7 | +2. if start index >= len(nums) : add path into result and return |
| 8 | +3. Choice : all the numbers in the unique array |
| 9 | +4. Choose : add one element at a time on path (this can be done by in recursive call by current choice index + 1 ) |
| 10 | +5. Explore : recursive cal on above choose and next choice |
| 11 | +6. Un-choose : remove the chosen element from path |
| 12 | +7. Explore : recursive cal for next choice |
12 | 13 |
|
13 | 14 | --------
|
14 | 15 | ### 39. Combination Sum
|
15 |
| - |
16 |
| - |
| 16 | +Need to find all possible combination of given target where numbers can be repetitive |
| 17 | +1. Intuition: Need to find all combination - hence backtracking. |
| 18 | + 1. Same as 78. Subset with once change, instead of choosing new number each time, chose same number until, |
| 19 | +2. if start index >= len(nums) and target == sum of path: add path into result and return |
| 20 | +3. if index >= len(nums) OR target > sum of path: return, it means that path does't contains the sum |
| 21 | +4. Choice: all the numbers |
| 22 | +5. Choose: One element until either target == sum of path |
| 23 | +6. Explore: recursive call for same start point |
| 24 | +7. Un-choose: remove the added element from path |
| 25 | +8. Explore: recursive call on next number |
17 | 26 |
|
18 | 27 |
|
19 | 28 |
|
|
0 commit comments