GATE Computer ScienceHardGATE CS (PYQ pattern)
The maximum of every window of 3 consecutive elements of [4, 2, 12, 11, -5, 7, 9, 3, 1, 6] is found with a deque of indices: before pushing index i, pop from the back while a[back] <= a[i]; push i; pop from the front if it has left the window. How many deque operations (back pops + pushes + front pops) are performed, and what is the sum of the window maxima?
- A. 17 operations, sum 80
- B. 19 operations, sum 80
- C. 19 operations, sum 73
- D. 22 operations, sum 82
Correct answer: B. 19 operations, sum 80
Window maxima are [12, 12, 12, 11, 9, 9, 9, 6] (sum 80). There are 10 pushes plus the pops from back and front, 19 operations in all.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A singly linked list has 25 nodes. A routine places pointer p at the head and pointer q at the 6th node from the head, then advances both…
- 12-bit sets are stored as bit vectors: A = 101101101101, B = 011010110011, C = 111000011010 (most significant bit first). What are the…
- int f(int a[], int l, int r) { if (l == r) return a[l]; int m = (l + r) / 2; int x = f(a, l, m), y = f(a, m + 1, r); return x > y ? x : y…
- Keys 50, 30, 70, 20, 40, 60, 80, 10, 35, 45, 65, 85, 5, 15, 32, 38, 90 are inserted in this order into an empty BST (root at depth 0)…
- A min-heap is built from [27, 5, 19, 3, 41, 8, 16, 2, 33, 11, 24, 7] by bottom-up heapify, and then extract-min (last element to the root…
- int m[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; for (int i = 0; i < 4; i++) for (int j = 0; j < i; j++) {…