Data Structures & AlgorithmsVery hard
How many index pairs i < j in 1 3 6 5 4 10 2 have A[i] + A[j] equal to a perfect square?
- A. 1
- B. 0
- C. 5
- D. 4
Correct answer: D. 4
Test each index pair's sum with an exact square check; the product and difference tests answer different questions, and equal values are not present here so the diagonal case does not matter.
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
- Choose three DIFFERENT positions of -10 -3 1 2 7 -1 to maximise the product of their values. What is the maximum product?
- How many ordered pairs (i, j) with i ≠ j in 3 1 4 1 5 satisfy A[i] > A[j]?
- 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?