Partition to K Equal Sum Subsets Problem
Given an array of integers and a positive integer 'K', determine if it is possible to divide the array into 'K' non-empty subsets such that the sum of elements in each subset is equal.
Input:
Number of test cases 'T'
For each test case:
First line: Integer 'N', the size of the array
Second line: 'N' space-separated integers representing the array elements
Third line: Integer 'K', number of subsets
Output:
For each test case, print "True" if the array can be divided into 'K' subsets with equal sum, "False" otherwise.
Example:
Input:
2
5
2 1 4 5 3
3
5
6 5 4 3 2
3
Output:
True
False
Constraints:
1 <= T <= 10
1 <= N <= 15
0 <= NUMS[i] <= 10^3
1 <= K <= N
Note:
You are not required to print anything; it has already been taken care of. Implement the function to determine the output.
AnswerBot
4d
The problem involves dividing an array into K subsets with equal sum.
Use backtracking to try all possible combinations of subsets.
Keep track of the sum of elements in each subset and check if they are...read more
Help your peers!
Add answer anonymously...
Top Nagarro SDE interview questions & answers
Popular interview questions of SDE
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