Data Structures & AlgorithmsHard
How many index pairs i < j in 0 1 2 2 3 4 0 satisfy A[i]·A[j] = A[i] + A[j]?
- A. 11
- B. 6
- C. 2
- D. 4
Correct answer: C. 2
The equation x·y = x + y rearranges to (x − 1)(y − 1) = 1, so the solutions are x = y = 0 or x = y = 2 (and pairs with 0). Counting index pairs with i ≤ j adds the diagonal, and a plain sum test checks a different equation.
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 1 2 2 4 3 5 consist of consecutive integers (their values, in some order, are k, k+1, …, k+L−1 with no…
- Each operation increases one element of 3 3 1 6 2 by 1. What is the minimum total number of operations to make the array STRICTLY…
- Using AT MOST ONE swap of two elements, what is the lexicographically smallest array obtainable from 3 1 2 5 4?
- How many contiguous subarrays of 3 1 4 1 5 9 2 6 contain the position of the global maximum value 9?
- For each contiguous window of size 3 in 4 2 12 3 8 1 7, take its minimum. What is the largest of these window minimums?
- For every contiguous window of size 3 in 4 2 12 3 8 1 7, take its minimum and add all these minimums. What is the total?