Data Structures & AlgorithmsHard
How many index pairs i < j in [1, 5, 3, 3, 3, 7, 2, 4, 6] have DD[i] + DD[j] = 6? Equal values at different indices are different pairs.
- A. 3
- B. 10
- C. 5
- D. 8
Correct answer: C. 5
Pairs are counted by index, so three equal 3s give three pairs of 3 + 3 among positions. A set of value pairs collapses repeats, counting ordered pairs doubles the answer, and including i = j adds self-pairs.
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 [2, 1, 3, 1, 1, 2, 4, 1] have each element sum equal to its length (sum of (a[i] − 1) over the subarray…
- How many contiguous subarrays of [1, 2, 1, 2, 3, 3, 4] contain exactly 2 distinct values?
- In the array [2, 7, 3, 7, 1, 4], how many contiguous subarrays have their LEFT-most element equal to the maximum of the subarray (ties…
- How many contiguous subarrays of [1, 2, 1, 3, 2, 2, 1] have equal first and last elements and length at least 2?
- Counting subarrays whose sum is divisible by k with prefix remainders, which statement is TRUE?
- Two pointers count subarrays of POSITIVE integers with sum at most K. Why can the left pointer only move forward as the right pointer moves?