Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
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?
- A. 5
- B. 2
- C. 4
- D. 3
Correct answer: D. 3
Count cells where the coverage count is at least two. Each interval contributes its length, so the total coverage exceeds the union; the excess over the union is not the same as the doubly-covered cells.
More Coding Interview Problems questions
- 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…
- 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…