Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many contiguous subarrays of [2, 8, 3, 3, 2, 6] have a product that is a perfect square?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
A product is a square exactly when every prime appears to an even power, so track the parity vector of square-free parts instead of multiplying out the values.
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 [1, 3, 2, 6, 4, 2] have a sum divisible by their length?
- Evaluate the integer expression 2 - 3 4 + 10 / 3 using standard precedence and integer division that truncates toward zero. What is the…
- What is the length of the longest run of consecutive integers (in any order) present in the array [9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6]?
- How many index pairs i < j in the array [1, 5, 3, 4, 2, 7, 9] have absolute difference exactly 2?
- In the array [1, 5, 5, 5, 5, 5, 5, 5, 5, 9], how many distinct value pairs {x, y} with x <= y satisfy x + y = 10, where x and y both occur…
- What is the length of the longest substring of aabccbb that can be made into a string of one repeated letter by replacing at most 2…