Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Array [2, 3, 5, 10, 2, 0, 1]. How many contiguous non-empty subarrays have a sum equal to exactly twice their maximum element?
- A. 5
- B. 6
- C. 4
- D. 9
Correct answer: A. 5
Checking every subarray directly is enough for this small array. Comparing the maximum with the sum without the factor of two counts a different set of subarrays.
More Coding Interview Problems questions
- 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…
- Problem: A directed graph on vertices 0–7 has arcs 0→1, 0→2, 1→3, 2→3, 3→4, 4→5, 2→6, 6→7. How many vertices are reachable from vertex 0…
- Problem: A 4×4 grid has obstacles at (1,1), (1,2), (2,1) (row, column, 0-indexed). Movement is up, down, left or right. How many distinct…
- Problem: An undirected graph on 9 vertices (0–8) has edges 0-1, 1-2, 3-4, 4-5, 5-3, 6-7. Vertex 8 is isolated. Count the unordered pairs…