Split Set to Equal Subsets
Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.
Description
We're given a set in the form of an array with a unique integers. Can you write a function that tells us whether it can be separated into two subsets whose elements have equal sums?
Here's an example: [5, 9, 7, 21]:

The below would return true because newSet can be divided into [5, 9, 7] and [21]. Both subsets sum to 21 and are equal.
function hasEqualSubsets(arr) {
// fill
}
const newSet = [5, 7, 21, 9]
console.log(hasEqualSubsets(newSet)); // true
And in another example, the below returns false since newSet cannot be divided into equal subsets.
const newSet = [9, 3, 1]
console.log(hasEqualSubsets(newSet)); // false

Constraints
- Length of the array <=
1000 - The values will always contain integer values between
-1000and1000 - The final answer will always fit in the integer value
- Expected time complexity :
O(n^2) - Expected space complexity :
O(n^2)
```js
function hasEqualSubsets(nums) {
// Fill in this method
return nums;
}
```
CONTINUE WITH ALGODAILY PREMIUM
Keep going with the complete tutorial.
Unlock the remaining explanations and exercises, alongside the full learning library.
Explore Premium →