Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many non-empty contiguous subarrays of [1, 3, 6, 10, 2, 6] have a sum that is a perfect square (including 1, 4, 9, ...)?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Check every subarray sum with an exact integer square-root test; the count of perfect-square sums is 4. Float square roots can misjudge large values, so the integer test matters.
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
- For the binary array [1, 0, 1, 1, 0, 1, 1, 1, 0, 1], you may flip at most 2 zeros to ones. What is the length of the longest run of ones…
- How many distinct strings appear among the rotations of "abab" (all n cyclic shifts, including the unshifted string)?
- What is the length of the longest substring of "aaabbbcaabbbcc" in which every letter occurring in it appears at least 3 times?
- How many contiguous subarrays of [1, 2, 3, 3, 2, 1, 4] have a bitwise XOR of exactly 0?
- Among pairs of distinct elements of [-8, -3, 1, 5, 9, 12], which pair sum is closest to the target 4? (Report the sum itself.)
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 1, 4, 2]?