
Asked in JPMorgan Chase & Co.
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...
Top Software Developer Interview Questions Asked at JPMorgan Chase & Co.
Q. Given a Python program, debug the program.
Q. What are the differences between a HashMap and a LinkedHashMap?
Q. Given an array of integers nums and an integer target, return indices of the two...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for JPMorgan Chase & Co. Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

