Data Structures & AlgorithmsHard
For [2, 3, 4, 6, 9, 5, 12], how many index pairs i < j have the product BB[i]·BB[j] divisible by 6?
- A. 15
- B. 6
- C. 17
- D. 18
Correct answer: A. 15
A product is divisible by 6 when it has a factor 2 and a factor 3, and those may come from different elements. Requiring both elements to be multiples of 3 misses many valid pairs, and including i = j double-counts self-pairs that are not pairs of distinct positions.
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 [5, 5, 3, 3, 6, 6, 6] have XOR equal to 0?
- 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.
- 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?