Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Smallest subarray with sum greater than x
Easy Accuracy: 47.73% Submissions: 21673 Points: 2

Given an array of integers (A[])  and a number x, find the smallest subarray with sum greater than the given value.

Note: There is at least one subarray with sum greater than x

Examples:
A[] = {1, 4, 45, 6, 0, 19}
   x  =  51
Output: 3
Minimum length subarray is {4, 45, 6}

A[] = {1, 10, 5, 2, 7}
   x  = 9
Output: 1
Minimum length subarray is {10}


Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two space separated integers N and x. Then in the next line are N space separated values of the array.

Output:
For each test case in a new line print the required ouput.

Constraints:
1<=T<=100
1<=N,x<=1000
1<=A[]<=1000

Example:
Input:

2
6 51
1 4 45 6 0 19
5 9
1 10 5 2 7
Output:
3
1

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Smallest subarray with sum greater than x

Output Window