Data Structures & AlgorithmsVery hard
In the sorted array [1, 1, 2, 2, 3, 4, 4, 5], how many different VALUE pairs {x, y} with x < y satisfy x + y = 6? (Repeated copies of a value do not create new value pairs.)
- A. 6
- B. 5
- C. 3
- D. 2
Correct answer: D. 2
Count distinct value pairs, so repeated copies collapse to one pair. Counting index pairs counts each copy separately, and allowing x = y (not asked) includes ordered duplicates.
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
- Among all permutations of 1, 2, 3, 4 in which no two ADJACENT entries sum to 5, which one is lexicographically smallest? Give it as a…
- What is the smallest positive integer that is NOT the sum of any CONTIGUOUS (adjacent) block of [1, 2, 4, 8]?
- How many ways can [1, 2, 3, 4, 5, 7] be cut into one or more contiguous, non-empty segments so that EVERY segment has an even sum?
- How many contiguous subarrays of [1, 2, 1, 3, 2, 1, 4, 2, 3] contain each of the values 1, 2, ..., L exactly once, where L is the subarray…
- How many contiguous subarrays of [1, 2, 3, 3, 2, 1, 4, 4] have even length and equal sums in their left half and right half?
- How many contiguous subarrays of [3, 1, 4, 1, 5, 9, 2, 6] have a sum that is divisible by their own maximum element?