Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 698 Partition to K Equal Sum Subsets - Problem Statement

LeetCode 698

Given an array nums and integer kk, determine if the array can be divided into kk non-empty subsets with equal sum. Example: nums =[4,3,2,3,5,2,1]= [4, 3, 2, 3, 5, 2, 1], k=4k = 4. Total =20= 20, target per subset =5= 5. Partition: {5},{4,1},{3,2},{3,2}\{5\}, \{4, 1\}, \{3, 2\}, \{3, 2\}. Return true.

This needs bitmask DP because you must track exactly which elements have been used. Standard sum-based DP can't distinguish different groupings that reach the same partial sum.