Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Sorted array [1, 2, 7, 8, 11, 15]. How many index triples i < j < k satisfy a[i] + a[j] + a[k] = 18?
- A. 2
- B. 0
- C. 1
- D. 3
Correct answer: C. 1
Fix the smallest element and use two pointers over the remaining sorted suffix to find pairs with the required sum; each match is one triple. Sum 17 is a neighbouring target that changes the count.
More Coding Interview Problems questions
- Four jobs have processing times [6, 3, 5, 2]. They run one at a time in some order, and job at position i (1-based) incurs cost i times…
- For the values [2, 5, 3, 8, 1, 6], how many values give remainder 1 or 2 when divided by 3 (counted once for each value)?
- Array [4, 4, 7, 1, 7, 2]. How many index pairs i < j have equal values a[i] = a[j]?
- Array [3, 7, 2, 9, 4]. How many contiguous subarrays sum to exactly 9?
- Problem: Fresh oranges (1) rot their neighbours (4-directional) one minute at a time; 0 is empty and 2 is rotten. How many minutes until…
- Problem: How many distinct palindromic substrings does 'aaaa' have? Run the code. python s = 'aaaa' print(len({s[i:j] for i in…