VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 08: Recursion and backtracking

Lesson 8.5 of 10 in this module Unrolled Pro

Combination Sum

All combinations of distinct candidates, each reusable any number of times, that sum to a target. From exploring every ordering and de-duplicating (permutations of each answer), to backtracking with a start index that stays on the same candidate for reuse, to sorting and breaking as soon as a candidate exceeds what's left. Then counting the combinations with dynamic programming instead of listing them, at most k numbers from 1 to 9, and splitting a global batch into micro-batches of allowed sizes.

about 10 min 5 Python examples 2 quick checks

Problem. Given distinct positive integers candidates and a target, return all unique combinations of candidates that sum to target. A candidate may be used any number of times. Combinations are unordered: [2, 2, 3] and [3, 2, 2] are the same.

text
candidates = [2, 3, 6, 7], target = 7    →   [2, 2, 3], [7]
candidates = [2, 3, 5],    target = 8    →   [2, 2, 2, 2], [2, 3, 3], [3, 5]
candidates = [2],          target = 1    →   (none)

Compared with lesson 8.4's combination sum II, two things change: no duplicates in the input, and reuse is allowed, so the recursion must be able to pick the same candidate again.

ML context. "Which multisets of allowed sizes add up to exactly this?" is a capacity question: splitting a global batch of 96 into micro-batches of sizes the kernels are tuned for, filling a node's GPU memory with replicas of different model sizes, composing a request budget from instance types. Often you need not the list but the count of ways, and that's a dynamic programming problem (Change A).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Combination Sum"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee