Rahul and Minimum Subarray Challenge

Rahul, who is passionate about programming, is learning about arrays and lists. He faces a challenging problem to determine the smallest subarray length in a given array 'ARR' of size 'N', where the subarray's sum exceeds a specified value 'X'. If such a subarray does not exist, the function should return 0.

Example:

Input:
ARR = [1, 2, 21, 7, 6, 12], X = 23
Output:
2
Explanation:

The smallest subarray with a sum greater than 'X' is [21, 7], with a length of 2. Although there are other subarrays, such as [1, 2, 21] and [7, 6, 12], this is the smallest possible.

Constraints:

  • 1 ≤ T ≤ 10^2
  • 1 ≤ N ≤ 10^3
  • 1 ≤ X ≤ 10^9
  • 0 ≤ A[i] ≤ 10^9
AnswerBot
1y

The problem is to find the length of the smallest subarray in a given array with its sum greater than a given value.

  • Iterate through the array and keep track of the current subarray sum

  • If the current s...read more

Help your peers!
Select
Add answer anonymously...

Decimal Point Analytics Software Developer Intern interview questions & answers

A Software Developer Intern was asked 8mo agoQ. Given an array of integers, find the first repeating element in the array.
A Software Developer Intern was asked 8mo agoQ. Define the four pillars of OOPS.
A Software Developer Intern was asked Q. Rahul and Minimum Subarray Challenge Rahul, who is passionate about programming,...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 8mo agoQ1. Given an array of integers, find the first repeating element in the array.
A Software Developer Intern was asked 8mo agoQ2. Define the four pillars of OOPS.
A Software Developer Intern was asked Q3. Rahul and Minimum Subarray Challenge Rahul, who is passionate about programming,...read more
Decimal Point Analytics Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits