Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
What is the maximum number of DISJOINT non-empty contiguous subarrays of [1, -1, 2, -2, 3, 4, -7, 5, -5, 6] that each have sum 0?
- A. 4
- B. 5
- C. 3
- D. 0
Correct answer: A. 4
dp[j] = max(dp[j−1], dp[i] + 1) over starts i with zero-sum a[i..j−1]: a greedy scan that resets the prefix set at each zero-sum match is the fast form. Both give the same count here.
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 possible length of a single CONTIGUOUS block of [1, 3, 7, 4, 2, 5, 9] that you can delete (the rest is concatenated in…
- The sorted numbers [1, 3, 6, 7, 10, 11, 15] must be split into the fewest CONTIGUOUS groups so that in each group the largest minus the…
- How many arrays of length 3 with entries from {1, 2, ..., 3} have a maximum entry of exactly 2?
- How many non-empty subsets of [4, 6, 9, 10, 15] (chosen by position) have a greatest common divisor equal to 1?
- What is the length of the longest contiguous subarray of [2, -3, 0, -1, 4, -2, 5, -1] whose product is strictly positive?
- Let P[0] = 0 and P[k] be the XOR of the first k elements of [3, 5, 6, 3, 1, 5, 2]. How many pairs of indices (i < j) among 0..7 have P[i]…