Data Structures & AlgorithmsVery hardGATE CS · DSA
What is the maximum product of a non-empty contiguous subarray of [3, 4, 3, 3, −2, −2, −1, 3]? (Track both the maximum and the minimum product ending at each index.)
- A. 108
- B. 4
- C. 432
- D. 433
Correct answer: C. 432
A negative number turns the smallest product into the largest, so keep (max, min) ending at each position and reset across zeros. The answer is 432; tracking only the running maximum gives 108.
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
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [3, 37, 10, 52, 30, 23…
- Records are sorted with a composite key. What is printed? python recs = [('anu', 80), ('zoya', 70), ('dev', 70), ('ravi', 70), ('meera'…
- Two sorted arrays of sizes m and n (m ≤ n) are given. What is the best possible time to find the median of their union?
- A circular queue in an array of size n uses front and rear indices and keeps one slot always empty. What is the maximum number of elements…
- Overlapping versus non-overlapping substring counts. What is printed? python s, p = "bbaabbbabaaa", "aa" over = sum(1 for i in…
- A sorted array was rotated to give [35, 45, 52, 68, 78, 1, 5, 12, 18, 27, 28]. Binary search finds the index of the minimum: while lo <…