Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many contiguous subarrays of [2, 8, 3, 2, 6, 1] have a product that is a perfect square?
- A. 5
- B. 21
- C. 6
- D. 1
Correct answer: C. 6
Track the parity vector of prime exponents; equal prefix vectors bound a square product. The squares are [2,8], [3,2,6], [3,2,6,1], [2,8,3,2,6], [2,8,3,2,6,1] and the single [1], total 6. Forgetting the one-element [1] gives 5; 21 counts all subarrays.
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
- What is the minimum number of characters that must be deleted from "abcbdab" to make it a palindrome?
- How many pairs of non-overlapping equal substrings of length 2 exist in "abababab" (positions i < j with j >= i + 2)?
- In the text "aaabaaaabaaa", count the occurrences of "aaa" whose starting index is a prime number (0-indexed).
- What is the sum over all adjacent pairs of [4, 2, 5, 1, 3] of the smaller of the two values?
- A shop has a 'buy 2, get the cheapest of the three free' deal. Items priced [3, 1, 4, 2, 5, 6] are bought in groups of three, with the…
- A circular list holds 1..10. Starting at 1, you count 4 nodes (including the current one) and delete the fourth, then continue counting…