Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
How many non-empty contiguous subarrays of [2, 2, 5, -1, 3, 4, 1] have a sum that is a perfect square (0 counts as a square)?
- A. 7
- B. 4
- C. 28
- D. 2
Correct answer: A. 7
Of the 28 subarray sums, the squares are 1 (once), 4 (three times), 9 (twice) and 16 (once), so 7; the one negative sum (−1) must be rejected before the square-root test. 4 counts distinct square values, 28 all subarrays, and 2 only the sums equal to 9.
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 non-empty subsets of [3, 1, 4, 2, 5] (chosen by position) have a sum between 4 and 7 inclusive?
- Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the…
- How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index…
- Deleting exactly one character from "110100" gives a new binary string each time. How many DISTINCT strings result?
- How many DISTINCT palindromic strings (of any length ≥ 1) occur as subsequences of "abab"?
- Count the index paths from position 0 to position 6 in the array [1, 3, 2, 4, 6, 5, 7] where each move goes from index i to a LATER index…