VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 12: Dynamic programming

Lesson 12.6 of 16 in this module Unrolled Pro

Partition Equal Subset Sum

Can an array be split into two groups with equal sums? Exactly when some subset sums to half the total. From trying every subset (2^n), to a table of which sums are reachable using the first i items (O(n · S)), to one row updated from high sums to low so each item is used once, and a Python integer used as a bitset that shifts all reachable sums at once. Then the smallest possible difference, more than two groups, the 0/1 knapsack it generalises, and balancing data shards across two GPUs.

about 10 min 3 Python examples 2 quick checks

Problem. Given positive integers nums, return whether they can be split into two subsets with equal sums.

text
nums = [1, 5, 11, 5]   →   True      ({1, 5, 5} and {11}: both 11)
nums = [1, 2, 3, 5]    →   False     (total 11 is odd)

If the total is odd, no. Otherwise the question is: does some subset sum to total / 2? (The rest automatically sums to the other half.) That's the subset-sum problem, the simplest 0/1 knapsack: each item is used at most once, and the DP state is "which sums are reachable".

ML context. Splitting work into equal halves: assigning data shards (with different numbers of tokens) to two GPUs so both finish together, splitting a dataset into two halves of equal size by whole groups (so no group straddles the split), balancing two pipeline stages by layer costs (lesson 5.8 for k stages). When an exact split isn't possible, the smallest difference (Change A) is what you want.


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 "Partition Equal Subset 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