Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
A subarray sums to 0 exactly when two prefix sums are equal, so count equal prefix values, including the empty prefix 0.
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
- In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i]…
- How many strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by…
- What is the edit distance (Levenshtein distance with insertion, deletion and substitution each costing 1) between intention and execution?
- What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?
- What is the rank (1-based, in lexicographic order) of the string cab among all permutations of the letters a, b, c?
- How many trailing zeros does 2024! have in base 10?