Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Sum of elements of smallest subarray greater than x

Easy Acceptance 50% Points 20

Given a number x and an array of integers arr, find the smallest subarray with sum greater than the given value. If such a subarray do not exist return 0 in that case.

Examples
Example 1

Example 1

Input: x = 51, arr[] = [1, 4, 45, 6, 0, 19]

Output: 3

Explanation: Minimum length subarray is [4, 45, 6]

Example 2

Example 2

Input: x = 100, arr[] = [1, 10, 5, 2, 7]

Output: 0

Explanation: No subarray exist

Constraints
  • 1 = arr.size, x = 10^5
  • 0 = arr[] = 10^4
Topics
Array
Companies
Amazon Meta Google Goldman Sachs
Added 18 Aug 2025 50% acceptance
Ln 1, Col 1Sign in to save your code
51
1 4 45 6 0 19
3