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
2mo
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 10mo agoQ. Write a Python program to find substrings from a list.
A Software Developer was asked 11mo agoQ. What are the differences between a HashMap and a LinkedHashMap?
A Software Developer was asked 14 Feb 2024Q. How do you implement caching in your application?
Popular interview questions of Software Developer
A Software Developer was asked 10mo agoQ1. Write a Python program to find substrings from a list.
A Software Developer was asked 11mo agoQ2. What are the differences between a HashMap and a LinkedHashMap?
A Software Developer was asked 14 Feb 2024Q3. How do you implement caching in your application?
>
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