Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Sorted array [1, 3, 4, 6, 8, 9, 11]. How many index triples i < j < k satisfy c[k] - c[i] <= 4?
- A. 7
- B. 4
- C. 6
- D. 5
Correct answer: D. 5
Fix the left index i and move the right pointer while the spread stays within 4; each valid right end contributes the number of values strictly between i and it. Strict bounds drop triples whose spread is exactly 4.
More Coding Interview Problems questions
- How many strings of length 5 over the alphabet {a, b, c} have no two adjacent characters equal?
- How many non-empty subsets of {1, 2, 3, 4, 5, 6} have an XOR of their elements that is at least 4?
- How many subsets (including the empty subset) of the values [2, 3, 5, 7, 11, 13, 4, 6] have a sum between 10 and 20 inclusive?
- The values [7, 4, 9, 2, 6, 5] are distributed among two groups (each value goes to exactly one group, any group may be empty). What is the…
- Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included…
- Half-open intervals [0,4), [1,3), [2,6), [5,7), [6,9), [8,10). What is the minimum number of integer points such that every interval…