
If ‘N’ : 3
Then the two groups can be : {3} and {2, 1}
The absolute difference of sum between above two groups is : 0
The first line of input contains an integer ‘T’ representing the number of test cases.
Then the test cases follow :
The only line of each test case contains a single integer ‘N’.
For each test case, print the minimum absolute difference of sum of each group.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^2
2 <= N <= 10^4
Time Limit : 1 sec
The naive approach for this is to generate all the possible sums by including i’th number in a group or not, and then find the optimal solution.
Here is the algorithm :
HELPER(‘SUM’, ‘i’, ‘group1Sum’)
Find the sum of all elements upto ‘N’ and divide it by 2 which will represent as the ‘SUM’ of a group. Add elements in the first group starting from ‘N’ till the ‘SUM’ is greater than the element else add it to another group.
Here is the algorithm :
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers