Z51

Partition to K Equal Sum Subsets

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: BOOLEAN

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) -> bool

Input & Output Contract

Output Rule:True veya False.

System Constraints

1 <= k <= sayilar.length <= 16
1 <= sayilar[i] <= 10^4

Example 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} -> True

Example Test Scenarios (3)

Example 1
Input:[[4,3,2,3,5,2,1],4]
Expected Output:true
Example 2: 10/3 Tam Bölünmez
Input:[[1,2,3,4],3]
Expected Output:false
Example 3: 4 Eşit Parça
Input:[[2,2,2,2],4]
Expected Output:true
Loading Python Editor...
Input Parameters
[
  [
    4,
    3,
    2,
    3,
    5,
    2,
    1
  ],
  4
]
Expected Output
true