Partition to K Equal Sum Subsets

Medium

Company Tags

You are given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.

Example 1:

Input: nums = [2,4,1,3,5], k = 3

Output: true

Explanation: Given array can be divided into three subsets [5], [2,3], [4,1].


Example 2:

Input: nums = [1,2,3,4], k = 3

Output: false

Constraints:

  • 1 <= k <= nums.length <= 16
  • 1 <= nums[i] <= 10,000
  • The frequency of each element is in the range [1, 4].


Company Tags

Please upgrade to NeetCode Pro to view company tags.

nums =

k =