Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many index pairs i < j in [5, 2, 8, 3, 1, 9] satisfy a[i] * a[j] <= 15?
- A. 15
- B. 8
- C. 7
- D. 3
Correct answer: B. 8
Sorted values 1, 2, 3, 5, 8, 9: two pointers find the pairs with product ≤ 15: (1,2), (1,3), (1,5), (1,8), (1,9), (2,3), (2,5), (3,5) = 8. Using < 15 drops (3,5) and gives 7, 15 counts all pairs, and 3 pairs only values ≤ √15.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 4, 2] that have length at least 2?
- Meetings are half-open intervals [s, e) listed as (1,4), (2,5), (3,6), (7,9), (8,10), (5,7). A meeting ending at time t and another…
- What is the smallest positive integer n such that 1 + 2 + ... + n is at least 500?
- What is the minimum number of elements to delete from [4, 9, 1, 6, 3, 8] so that the remaining elements have maximum minus minimum at most…
- How many proper borders (non-empty prefixes that are also suffixes, excluding the whole string) does "abacabab" have?
- Rotate "abcabd" one step to the left, then count the distinct substrings of length 3 in the rotated string.