Data Structures & AlgorithmsModerateCodeforces Div2 C · TCS NQT
How many unordered pairs of different positions in [3, 8, 2, 9, 5, 4] have a product at most 24?
- A. 10
- B. 14
- C. 9
- D. 8
Correct answer: C. 9
Sort the array; for each i, the valid j form a prefix (values increase), so a two-pointer or binary search over the sorted array counts them in O(n log n). Using a fixed multiplication threshold per pair without sorting is slower and easy to get wrong at the boundary.
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 smallest period of the string "abaababaab"? The smallest period p is the least p > 0 such that s[i] = s[i + p] for every valid…
- What is the length of the longest proper border of "abacabacabab"? A border is a non-empty proper prefix that is also a suffix.
- Array [2, 3, 1, 4, 2, 5, 1, 2]: from index i you may jump to any index j with i < j ≤ i + a[i]. Landing on index j costs a[j]. Starting at…
- How many strictly increasing sequences of length 4 can be formed from the values 1 to 10 (each sequence uses four distinct values, listed…
- The sorted array [1, 2, 4, 5, 9, 10] is given. What is the smallest positive integer that does NOT appear in it?
- How many DISTINCT strings are produced by taking all cyclic rotations of "abcabcab" (including the original)?