K Subsets with Equal Sum Problem Statement
Determine whether it is possible to partition an array ARR
into K
subsets, each having an equal sum.
Example:
Input:
ARR = [3, 5, 2, 4, 4], K = 2
Output:
true
Explanation:
The array can be divided into two subsets with equal sum: [4, 5] and [2, 3, 4], each summing up to 9.
Constraints:
1 <= T <= 100
1 <= N <= 1000
1 <= K <= 20
1 <= ARR[i] <= 1000
Note:
Each element in the array must belong to only one subset.
Input:
The first line contains an integer 'T', the number of test cases.
Each test case consists of two lines:
The first line contains two integers, 'N' (length of the array) and 'K' (number of subsets).
The second line contains 'N' space-separated integers, the elements of the array ARR.
Output:
For each test case, return true if partition into 'K' equal sum subsets is possible, otherwise return false.
Be the first one to answer
Add answer anonymously...
Top Nagarro Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app