The idea is allocate number into bucket. Start from large number with reduce DFS calls.

Target is sum of each group, equals sum / k.

```
public boolean canPartitionKSubsets(int[] nums, int k) {
if(nums == null || nums.length == 0) return false;
int sum = 0;
for(int num: nums) sum += num;
if(sum % k != 0) return false;
Arrays.sort(nums);
int[] bucket = new int[k];
return dfs(nums, bucket, nums.length - 1, sum / k);
}
public boolean dfs(int[] nums, int[] bucket, int index, int target) {
if(index == -1) return true;
for(int i = 0; i < bucket.length; i++) {
if(bucket[i] + nums[index] <= target) {
bucket[i] += nums[index];
if(dfs(nums, bucket, index - 1, target)) return true;
bucket[i] -= nums[index];
}
}
return false;
}
```