Data Structures & AlgorithmsModerate
How many ordered pairs (i, j) with i ≠ j in 3 1 4 1 5 satisfy A[i] > A[j]?
- A. 3
- B. 9
- C. 11
- D. 10
Correct answer: B. 9
Count each ordered pair separately: a pair with unequal values contributes exactly once in the order that puts the larger first. Counting unordered pairs, unequal pairs, or using ≥ (which admits equal values) gives other totals.
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
- How many contiguous subarrays of 3 2 5 4 7 6 1 8 have a PRIME length and an EVEN sum?
- How many contiguous subarrays of 2 9 4 7 1 8 3 have their MAXIMUM value located at an EVEN absolute index of the original array (index 0…
- How many index pairs i < j in 4 1 7 2 10 5 8 satisfy A[i] ≡ A[j] (mod 3) AND A[i] < A[j]?
- How many contiguous substrings of "abaabbaab" contain EXACTLY one 'b' and at least two 'a's?
- What is the maximum sum of a contiguous subarray of 3 5 2 7 9 1 4 11 in which every element is ODD?
- How many contiguous subarrays of 1 3 4 7 9 6 11 of length at least 2 contain EXACTLY one even value?