totalSum
.dp
with size totalSum + 1
, where each element is an integer representing possible subset sizes for that sum.dp
.A[i]
, update dp[s+A[i]]
by OR-ing it with dp[s]
shifted left by 1 bit.n-1
.len
, check if the sum totalSum * len / n
is achievable by checking the len-th
bit in dp[totalSum * len / n]
.true
; otherwise, return false
after the loop.