Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
What is the length of the shortest contiguous subarray of [5, 1, 4, 3, 2, 6, 7] whose sum is at least 15?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
A two-pointer scan over positive numbers finds the shortest qualifying window, and checking every window confirms it. Taking the first qualifying window instead gives a longer one.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- In [6, 3, 6, 9, 3, 9, 9, 5, 5] exactly one value appears an odd number of times and every other value appears an even number of times…
- How many index pairs i < j in [12, 21, 30, 43, 66, 111, 3] have equal decimal digit sums?
- How many ordered index pairs (i, j) in [1, 3, 4, 7, 10, 12, 15] satisfy a[j] - a[i] = 3?
- How many integers from 1 to 10000 inclusive are multiples of 7 whose decimal digit sum is exactly 7?
- For "aabaabaa", how many indices i >= 1 have Z-function value exactly 2?
- How many ordered pairs (a, b) of integers with a >= 2 and b >= 2 satisfy a b = 36?