Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Sum of elements of smallest subarray greater than x

Easy Acceptance 50.00% Points 20.00

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

Hints
Hint 1
NA
Constraints
  • 1 = arr.size, x = 10^5
  • 0 = arr[] = 10^4
Companies
Amazon Meta Google Goldman Sachs
Topics
Array
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions