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.

AnswerBot
4mo
Find the length of the smallest subarray in a given array whose sum exceeds a specified value.
Iterate through the array while keeping track of the sum of the current subarray.
Use two pointers to maint...read more
Help your peers!
Add answer anonymously...
JPMorgan Chase & Co. Software Developer interview questions & answers
A Software Developer was asked 1w agoQ. Given a directed graph, determine if it contains a cycle.
A Software Developer was asked 12mo agoQ. Given a Python program, debug the program.
A Software Developer was asked Q. What are the differences between a HashMap and a LinkedHashMap?
Popular interview questions of Software Developer
A Software Developer was asked 12mo agoQ1. Given a Python program, debug the program.
A Software Developer was asked Q2. What are the differences between a HashMap and a LinkedHashMap?
A Software Developer was asked Q3. Given an array of integers nums and an integer target, return indices of the two...read more
>
JPMorgan Chase & Co. Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

