Data Structures & AlgorithmsModerateTCS NQT · Infosys
Arrays A = [2, 5, 3, 7] and B = [4, 6, 1, 9]. How many pairs (x from A, y from B) satisfy 10 <= x * y <= 40?
- A. 13
- B. 16
- C. 8
- D. 11
Correct answer: C. 8
Of the 16 products, those in [10, 40] are 12, 12, 18, 18, 20, 27, 28, 30: 8 pairs (sorting B and binary searching each x does it in O(n log n)). Dropping the lower bound gives 13, dropping the upper bound gives 11, and 16 counts every pair.
More Coding Interview Problems questions
- Trains arrive at 100, 140, 150, 180, 200 and depart at 120, 160, 190, 210, 230 (times are not paired). A platform holds one train at a…
- Array [1, 2, 1, 3, 2, 2]. How many contiguous subarrays contain exactly two distinct values?
- Sorted arrays [2, 6, 9, 14] and [4, 7, 11, 15] are merged into one list. How many elements of the merged list lie strictly between 5 and 12?
- Choose a from {6, 9, 12} and b from {3, 5, 10}. What is the largest possible value of a XOR b?
- Tasks AAABBC must be scheduled one per time unit; two identical tasks need at least 2 idle-free units between them (cooldown k = 2, i.e…
- Half-open intervals [1,5), [3,8), [10,12), [11,15). How many integer points lie in at least one of these intervals?