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
1d

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
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter