Combination Sum III | Leetcode | Medium | Java | Recursion | Striver's A to Z DSA Sheet

preview_player
Показать описание
Combination sum III is a famous question and is frequently asked in interviews. This can be easily solved using recursion by Pick and Not-pick technique but you need a little familiarity with recursion if you want to solve this on your own.

Other problems for practice on leetcode:
Рекомендации по теме
Комментарии
Автор

Nice explanation. The best part about your explanations are you demostrate through dry run and then provide simple solutions.

UjjwalMishra-sccl
Автор

Hello didi, i was trying this question. My code is slightly different from you.

class Solution {
List<List<Integer>> ans = new ArrayList<>();
List<Integer> res = new ArrayList<>();

public List<List<Integer>> combinationSum3(int k, int n) {
// helper(1, k, n);
helper2(1, k, n, 0);
return ans;
}

public void helper2(int i, int size, int target, int sum) {
if (i > 9) {
return;
}

if (sum == target && res.size() == size) {
ans.add(new ArrayList<>(res));
return;
}

sum += i;
res.add(i);
helper2(i + 1, size, target, sum);

sum -= i;
res.remove(res.size() - 1);
helper2(i + 1, size, target, sum);
}
}

Can you please tell my why it is failing for the case (9, 45)

arnabsarkar
Автор

To the point explanation, loved it >>💖

kanpuriya_engineer
Автор

Keep posting such videos❤ I love your channel and the solution you providing💯

letscrackthecodewithshweta
Автор

Amazing Explanation, keep doing the same work!

shi-
Автор

didi put abit more effort in sudo code and algo
and then again dry run the code.... cuz beginners like me will love to watch and help you grow

Shauryacious
visit shbcf.ru