Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many contiguous subarrays of [1, 2, 3, 4] have a sum that is a perfect square?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Enumerate all ten subarrays and test each sum for being a perfect square.
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
- A string "cdeab" is rotated left by some number of steps k (0 <= k < 5) to become "abcde". What is the smallest such k?
- What is the sum of the maximum over all contiguous subarrays of [3, 1, 2, 4]?
- How many contiguous subarrays of [2, 1, 3, 4, 2] have a sum in the inclusive range [5, 7]?
- What is the number of 1-bits in the bitwise OR of 6, 10 and 12?
- For the array [1, -1, 2], how many distinct values appear among its prefix sums, counting the empty prefix 0?
- Four items of weight 4 each must be shipped in 2 boxes of equal capacity C (each box must hold whole items). What is the smallest feasible…