Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Positive array [2, 7, 1, 8, 3, 4, 6]. What is the largest possible sum of a contiguous subarray that does not exceed 15?
- A. 13
- B. 15
- C. 31
- D. 10
Correct answer: B. 15
A sliding window (all values positive) finds 7 + 8 = 15 and also 8 + 3 + 4 = 15, the cap exactly. Using < 15 gives 13, ignoring the cap gives the total 31, and growing a window only from the start gives 2 + 7 + 1 = 10.
More Coding Interview Problems questions
- Half-open intervals [1,5), [3,8), [6,10), [9,12) are given. How many integer points x are covered by at least two of these intervals?
- Half-open intervals [0,4), [3,7), [6,9), [8,12). How many unit cells [x, x+1) are covered by two or more intervals?
- Array [2, 3, 5, 10, 2, 0, 1]. How many contiguous non-empty subarrays have a sum equal to exactly twice their maximum element?
- How many pairs of integers (x, y) with 1 <= x < y <= 12 satisfy x XOR y = x + y?
- Sorted side lengths [3, 5, 7, 9, 11, 13]. How many triples of distinct sides form a non-degenerate triangle with perimeter at most 20?
- Problem: A 3×4 grid holds entry costs (row by row): [[1, 3, 1, 2], [1, 5, 1, 9], [4, 2, 1, 1]]. Starting at the top-left cell, you may…