Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
Over all pairs of DIFFERENT positions of [2, 5, 3, 8, 4], take the product of each pair and sort all these products. What is the 6-th smallest product (with multiplicity)?
- A. 15
- B. 20
- C. 16
- D. 17
Correct answer: C. 16
Binary search the product value x, counting pairs with product ≤ x by a two-pointer sweep over the sorted array; the smallest x with count ≥ k is the answer. Taking the k-th pair in input order, or the k-th largest, gives a different value.
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
- Starting from [9, 6, 15, 4], repeat 3 times: take the current LARGEST element, replace it by its floor half, and keep the others. What is…
- How many substrings of "cbaebabacd" of length 3 are anagrams of "abc" (contain exactly the same letters with the same counts, in any order)?
- In "abababaabab", what is the maximum number of NON-OVERLAPPING occurrences of "aba" that can be chosen (left to right, each occurrence…
- A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many…
- From "bcabcdbac" delete exactly 3 letters (the rest keep their order). What is the lexicographically LARGEST string you can obtain?
- In [3, 4, 9, 5, 6, 2, 1, 7, 8], what is the length of the longest subsequence (keeping the order) in which every pair of consecutive…