Z51
Partition to K Equal Sum Subsets
Problem Statement & Objective
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.
Function Signature (Python)
partition_to_k_equal_sum(nums: list[int], k: int) -> boolInput & Output Contract
Output Rule:True veya False.
System Constraints
1 <= k <= sayilar.length <= 16
1 <= sayilar[i] <= 10^4Example Execution Walkthrough
sayilar = [4, 3, 2, 3, 5, 2, 1], k = 4
toplam = 20, hedef alt küme toplamı 5
{5}, {1, 4}, {2, 3}, {2, 3} -> TrueExample Test Scenarios (3)
Example 1
Input:
[[4,3,2,3,5,2,1],4]Expected Output:
trueExample 2: 10/3 Tam Bölünmez
Input:
[[1,2,3,4],3]Expected Output:
falseExample 3: 4 Eşit Parça
Input:
[[2,2,2,2],4]Expected Output:
true