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.

AnswerBot
4mo
Yes, it is possible to partition an array into K subsets with equal sum.
Check if the total sum of the array is divisible by K.
Use backtracking to try all possible combinations of subsets.
Keep track of...read more
Help your peers!
Add answer anonymously...
Nagarro Software Developer interview questions & answers
A Software Developer was asked 8mo agoQ. Explain Kafka and how you would implement it.
A Software Developer was asked 9mo agoQ. Is the directory a file?
A Software Developer was asked 9mo agoQ. What is memory segmentation?
Popular interview questions of Software Developer
A Software Developer was asked 3mo agoQ1. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 3mo agoQ2. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
A Software Developer was asked 5mo agoQ3. What is abstraction in Java?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

