Data Structures & AlgorithmsHardProduct company OA
A deque of indices gives the MINIMUM of every window of size 3 in [4, 2, 12, 3, 8, 1, 7]. What are the window minima?
- A. 2, 2, 3, 1, 1
- B. 2, 2, 3, 3, 1
- C. 4, 2, 3, 1, 1
- D. 2, 3, 3, 1, 1
Correct answer: A. 2, 2, 3, 1, 1
Windows: [4 2 12] → 2, [2 12 3] → 2, [12 3 8] → 3, [3 8 1] → 1, [8 1 7] → 1. The deque keeps increasing values; 3 evicts 12, and 1 evicts 8 and 3. '3, 3' for the fourth window ignores the newly arrived 1.
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
- A hash table of size 10 uses linear probing. Slots 2, 3, 4, 7 and 8 are occupied and all others are empty (no deletions have happened). An…
- Quickselect with Lomuto partition (pivot = last element) looks for the 3rd smallest element of [7, 2, 9, 4, 3, 8], recursing only into the…
- Binary search finds the index of the minimum of the rotated sorted array [15, 18, 22, 3, 6, 9, 12] using: mid = (lo + hi) / 2; if a[mid] >…
- The sorted array [3, 4, 7, 10, 11] contains some positive integers. What is the 4th positive integer MISSING from it?
- For [2, 3, 0, 4], out[i] is the product of all elements except a[i], computed with prefix and suffix products (no division). What is out?
- The intervals [1, 4], [6, 8], [2, 3], [8, 10], [12, 13] are sorted by start and merged (intervals that touch at an endpoint also merge)…