Rahul And Minimum Subarray Problem Statement
Rahul is mastering arrays. He is tasked to find the length of the smallest contiguous subarray in a given array/list ARR
of size N
, such that its sum exceeds a specified value. Return 0
if no such subarray exists.
Input:
The first line contains a single integer ‘T’ representing the number of test cases. The first line of each test case will contain two integers ‘N’ and ‘X’ that denote the size of the ‘ARR’ and the given value respectively. The second line of each test case contains ‘N’ space-separated integers, these are the elements of ‘ARR’.
Output:
For each test case, output an integer indicating the length of the smallest subarray whose sum is greater than ‘X’. Each test case's output should appear on a new line.
Example:
Given ARR
= [1, 2, 21, 7, 6, 12] and X
= 23, the smallest subarray's length is 2
, as the subarray is [21, 7].
Constraints:
1 <= T <= 10^2
1 <= N <= 10^3
1 <= X <= 10^9
0 <= A[i] <= 10^9
Note:
You don’t need to print anything as it is handled automatically.
Be the first one to answer
Add answer anonymously...
Top JPMorgan Chase & Co. Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in JPMorgan Chase & Co. Software Developer
>
JPMorgan Chase & Co. Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app