Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
Array [2, 8, 9, 18, 4, 16, 6, 3]. How many index pairs i < j have a[i] * a[j] equal to a perfect square?
- A. 8
- B. 5
- C. 2
- D. 6
Correct answer: D. 6
A product of two integers is a perfect square when they have the same squarefree part. Grouping values by squarefree part and adding C(group, 2) counts these pairs; the sum-based check is a different condition.
More Coding Interview Problems questions
- Array [1, 2, 4, 3, 0, 5, 6]. What is the length of the longest contiguous subarray in which the XOR of the elements equals their sum?
- Ropes of lengths 4, 3, 2 and 6 are joined two at a time; joining ropes of lengths x and y costs x + y and creates one rope of length x +…
- Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?
- Set A = {1, 2, 4, 7} and set B = {3, 5, 6, 8}. Choose two different elements from A and two different elements from B. How many choices…
- Half-open intervals [0,2), [1,3), [2,4), [3,5), [4,6). What is the minimum number of intervals to remove so the remaining intervals are…
- Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?