Data Structures & AlgorithmsHard
How many contiguous subarrays of 1 2 3 1 2 1 4 have the sum of their elements at EVEN relative positions equal to the sum at ODD relative positions (positions counted from the subarray's own start)?
- A. 12
- B. 0
- C. 3
- D. 2
Correct answer: D. 2
Relative positions restart at each subarray's start, so the test is on the subarray's own even and odd positions. Parity of the total sum or the even-length restriction changes which blocks qualify.
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 contiguous subarrays of 2 5 1 5 3 4 contain the maximum VALUE of the subarray exactly once?
- What is the length of the shortest contiguous subarray of 1 4 4 2 2 1 3 whose sum is at least 9?
- Among the contiguous windows of length exactly 3 in 2 4 1 6 3 8 5 10 that contain at most one ODD number, what is the largest window sum?
- Choose three DIFFERENT positions from -4 -1 1 2 5 7 and add their values. Among all such three-element sums that are closest to 3 (in…
- How many contiguous subarrays of 4 2 3 6 5 7 1 have length equal to (maximum − minimum + 1)?
- What is the length of the longest contiguous subarray of 3 -2 0 4 -1 0 2 -5 in which the number of positive elements equals the number of…