As reported: Cisco Analyst (intern), campus technical round (2025, about 55 minutes): two coding questions after a project discussion; the first was the smallest subarray with sum greater than X, solved with a sliding window and explained with complexity analysis.
Given an array of non-negative integers arr and an integer x, return the length of the shortest contiguous subarray whose sum is strictly greater than x. Return 0 if no such subarray exists.
Example 1
arr = [1,4,45,6,0,19], x = 51
Output: 3 ([4,45,6] sums to 55)
Example 2
arr = [1,10,5,2,7], x = 9
Output: 1 ([10])
Example 3
arr = [1,2,4], x = 8
Output: 0
Constraints: 1 ≤ arr.length ≤ 10⁵; 0 ≤ arr[i] ≤ 10⁴; 0 ≤ x ≤ 10⁹.
Code runner format: two lines: arr (JSON array) and x. Implement smallestSubarray(arr, x); the harness prints the length.