Data Structures & AlgorithmsHardAmazon · Microsoft coding round
For the array [1, 3, -1, -3, 5, 3, 6, 7, 2, 9], consider every window of 4 consecutive elements. The sum of the maximum of each window is:
- A. 45
- B. 39
- C. 42
- D. 38
Correct answer: C. 42
The seven windows have maxima 3, 5, 5, 6, 7, 7, 9, which sum to 42. A deque-based sliding window maximum computes this in O(n); window sizes 3 and 5 would give 45 and 39.
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 circular queue uses an array of size 5 with the convention that front is the index of the next element to dequeue, rear is the index of…
- The integers 1, 2, 3, 4, 5, 6 are pushed onto an initially empty stack in this order; pops may happen at any time, and the 6 popped values…
- A hash table of size 11 uses double hashing: the probe sequence for key k is (k mod 11 + i · (7 − (k mod 7))) mod 11 for i = 0, 1, 2…
- A hash table of size 7 uses h(k) = k mod 7 with linear probing. A delete leaves a tombstone, an insert goes into the first empty or…
- A circular queue is stored in an array of size 6 (indices 0-5). Initially empty, front = 0, and an enqueue stores at index (front + count)…
- A singly linked list holds 1, 2, ..., 11 in order. Starting from the head, every alternate group of k = 3 consecutive nodes is reversed in…