#698
Partition to K Equal Sum Subsets
expert · 1030 · lc medium +32 · verified · 38.5% accepted · 7,531 likes · top 17%
Description
Given an integer array nums and an integer k, determine whether nums can be partitioned into k non-empty groups each with the same sum. Return true if possible, false otherwise.
Example 1:
Input: nums = [4,3,2,3,5,2,1], k = 4
Output: true
Explanation: It is possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums.
Example 2:
Input: nums = [1,2,3,4], k = 3
Output: false
Code
1
2
3