Data Structures & AlgorithmsHard
How many contiguous subarrays of 1 3 2 4 5 3 1 6 have a sum divisible by 4 AND an odd length?
- A. 6
- B. 3
- C. 7
- D. 4
Correct answer: B. 3
Both conditions must hold on the same subarray: the sum test uses the residue mod 4 and the length test uses parity. Dropping the length test, reversing the parity, or testing evenness of the sum instead changes the total.
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 index pairs i < j in 2 3 4 6 8 12 9 satisfy A[i]·A[j] = 24?
- A min-stack stores a pair (value, current minimum) per entry. Why does popping never require recomputing the minimum?
- In the 'remove nodes with a greater value to their right' problem, which list order is processed to decide survivors in O(n)?
- In the asteroid collision problem, why does a stack of right-moving asteroids suffice?
- A linear-time check decides whether a permutation can be sorted by one stack. Which property is equivalent to being stack-sortable?
- In the jump game (minimum number of jumps), why does a single left-to-right scan with a 'current boundary' count the jumps correctly?