Sets of Equal sum
Given an integer n, consider the set of numbers {1,2,3,…,n}. The task is to divide this set into two subsets such that every number from 1 to n belongs to exactly one subset and the sum of elements in both subsets is equal.
The goal is to count the number of distinct ways to form such a partition, where two partitions are considered the same if they differ only by swapping the subsets.
Since the answer can be large, return it modulo 109 +7
Example 1:
Input: n = 3
Output: 1
Explanation: Total sum: 1 + 2 + 3 = 6
Each set must sum to:
6 / 2 = 3
Valid partition:
{1,2} and {3}
Total ways = 1
Example 2:
Input: n = 4
Output: 1
Explanation: Total sum: 10
Target sum per set:
5
Valid split:
{1,4} and {2,3}
Now Your Turn!
Pick the correct output for the given inputInput: n = 7
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 500