Data Structures & AlgorithmsVery hardProduct company OA
What is the maximum product of a non-empty contiguous subarray of [2, −3, 0, −2, −4, 3, −1]?
- A. 8
- B. 24
- C. 6
- D. 2
Correct answer: B. 24
Track both the max and min product ending at each index (a negative times the min can become the max). After the 0 resets: −2, −4 → 8; × 3 → 24; × −1 → −24 (but the min −24 is not the answer). 24 from [−2, −4, 3]. Including the trailing −1 makes the product negative; across the 0 everything is 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
- What is the next lexicographic permutation of [1, 5, 8, 4, 7, 6, 5, 3, 1]?
- Circular route: station i gives gas[i] and driving to station i + 1 costs cost[i], with gas = [3, 1, 5, 2, 6] and cost = [4, 3, 2, 4, 2]…
- A monotonic stack removes duplicate letters so that each letter appears exactly once and the result is the lexicographically SMALLEST…
- 20 keys are hashed independently and uniformly into 100 slots. What is the EXPECTED number of colliding pairs (unordered pairs of keys…
- How many contiguous subarrays of [1, 3, 2, 4, 6, 5] satisfy max − min ≤ 2? (Two monotonic deques shrink the window from the left.)
- What is the smallest positive integer missing from [3, 4, −1, 1, 7, 2, 2, 9]? (In-place cyclic placement: put each value v with 1 ≤ v ≤ n…