Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Half-open intervals [1,5), [3,8), [10,12), [11,15). How many integer points lie in at least one of these intervals?
- A. 12
- B. 14
- C. 9
- D. 15
Correct answer: A. 12
Merge the overlapping intervals first: [1,8) covers seven points and [10,15) covers five, giving twelve. Adding the raw lengths double-counts the overlaps, which is the trap.
More Coding Interview Problems questions
- Array [5, -5, 2, 3, -2, 7, 3]. How many contiguous subarrays have a sum that is 0, 5 or 10?
- Sorted positive array [1, 3, 4, 6, 9, 12]. How many index pairs i < j have a[i] a[j] >= 18?
- How many integers x with 1 <= x <= 64 have a binary representation (without leading zeros) that reads the same forwards and backwards?
- Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for…
- Problem: How many topological orders does the DAG with edges 0->2, 1->2, 2->3 on vertices 0..3 have? Run the brute-force code. python from…
- Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row…