
Asked in Nagarro
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...
Top Software Developer Interview Questions Asked at Nagarro
Q. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
Q. Given the root of a binary search tree, and an integer k, return the kth smalles...read more
Q. What is abstraction in Java?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Nagarro Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
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

