Let’s say you have an array/list [1, 3, 5, 3] and ‘X’ is 7. We can first remove the rightmost element i.e. 3. The array becomes [1,3,5]. In the next step, we can remove the leftmost element i.e 1. The array becomes [3,5] and the sum of removed elements so far becomes 4. In the next step, we can remove the leftmost element i.e 3. The array becomes  and the sum of removed elements so far is 7. We have reached our target X i.e 7. Therefore the minimum number of operations to reach ‘X’ is 3.
The first line contains a single integer ‘T’ representing the number of test cases. The first line of each test case contains two single space-separated integers ‘N’ and ‘X’ representing the size of the array/list ‘ARR’ and the target you need to reach. The second line and the last line of input contain ‘N’ single space-separated integers representing the array/list elements.
For each test case print the minimum number of operations such that the sum of removed elements becomes exactly ‘X’.If it is not possible print -1. Print the output of each test case in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10 1 <= N <= 1000 1 <= X <= 10^9 1 <= ‘ARR[i]’ <= 10^6 Where ‘ARR[i]’ is an element of array/list ARR. Time Limit: 1sec
Best time to buy and sell stock II
Ninja And The Class Room