

You have been given an array/list ‘arr’ of integers consisting of ‘n’ integers which are the weight of ‘n’ balls. Your task is to return the size of the smallest subset of balls whose weight is greater than the weight of the remaining balls.
Example:You have 3 balls of weight 1, 2, and 3. You can take subset (1, 3) or (2, 3) as their total weight is greater than the weight of the remaining balls. The answer will be 2.

Green balls are taken in a subset.
Note:
You do not need to print anything; it has already been taken care of. Just implement the function.
The first line contains a single integer ‘t’ representing the number of test cases.
The first line of each test case contains a single integer ‘n’ representing the size of the array/list.
The second line and the last line of input contains ‘n’ single space-separated integers representing the array/list elements.
Output Format:
For each test case return the size of the smallest subset.
1 <= T <= 10
1 <= N <= 1000
1 <= ‘arr[i]’ <= 10^6
Where ‘T’ is the number of test cases.‘N’ is the number of elements in the array/list. ‘arr[i]’ is the weight of the ith ball.
Time Limit: 1sec
2
2
1 2
2
1 1
1
2
Test case1:
All the possible subsets are:-
{1} → Total weight of balls in subset 1.Sum of weights of remaining balls 2.It is an invalid subset since the weight of balls in the subset is not greater than the weight of the remaining balls.
{2} → Total weight of balls in subset 2.Sum of weights of remaining balls 1. It is a valid subset since the weight of balls in the subset is greater than the weight of the remaining balls.
{1,2} → Total weight of balls in subset 3.Sum of weights of remaining balls 0.It is a valid subset since the weight of balls in the subset is greater than the weight of the remaining balls.
Therefore the minimum subset size is 1.
Test case 2:
All the possible subsets are:-
{1} → Total weight of balls in subset 1.Sum of weights of remaining balls 1.It is an invalid subset since the weight of balls in the subset is not greater than the weight of the remaining balls.
{1,1} → Total weight of balls in subset 2.Sum of weights of remaining balls 0.It is a valid subset since the weight of balls in the subset is greater than the weight of the remaining balls.
Therefore the minimum subset size is 2.
2
7
15 5 11 13 17 10 20
8
1 2 3 4 4 3 2 1
3
3
Naively iterate over all subsets.
We have a simple recursion to solve this problem. Since the sum of all the balls remains constant we will just maintain the sum of weights of balls that we have taken in the subset.
We can declare ‘ans’, ‘arr’ and ‘totalSum’ as global variables.
We will define a recursive function with parameters ‘currIdx’, ‘totalSubsetSum’, and ‘ctr’.
O(‘n*2^n’), where ‘n’ denotes the size of array/list.
For an array/list of size ‘n’, we will have ‘2^n’ subsets and we will be iterating through them which gives another factor of ‘n’.
O(‘n’), where ‘n’ denotes the size of the array/list.
As we recurse we build a stack of ‘n’ size at max.