Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the deque index for the first element.
DSA C
deque[0] = [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first index.
Initializing deque with -1 which is invalid index.
✗ Incorrect
The deque should start with the index 0 of the first element.
2fill in blank
mediumComplete the condition to remove indices from the back of the deque if current element is greater.
DSA C
while (rear >= front && arr[i] [1] arr[deque[rear]]) { rear--; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong removals.
Using '>=' which may remove equal elements unnecessarily.
✗ Incorrect
We remove from the back while current element is greater than elements at those indices.
3fill in blank
hardFix the error in the condition to remove indices out of the current window from the front.
DSA C
if (deque[front] [1] i - k + 1) { front++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' removes valid indices too early.
Using '>=' or '>' reverses the logic.
✗ Incorrect
We remove indices strictly less than the window start index.
4fill in blank
hardFill both blanks to correctly assign the maximum for the current window and update the deque.
DSA C
max_values[i - k + 1] = arr[deque[[1]]]; deque[++rear] = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using rear instead of front for max index.
Adding wrong index to deque.
✗ Incorrect
Maximum is at deque front; add current index i to deque rear.
5fill in blank
hardFill all three blanks to complete the sliding window maximum function using deque.
DSA C
for (int i = 1; i < n; i++) { while (rear >= front && arr[i] [1] arr[deque[rear]]) { rear--; } deque[++rear] = [2]; if (deque[front] [3] i - k + 1) { front++; } if (i >= k - 1) { max_values[i - k + 1] = arr[deque[front]]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators causing incorrect deque updates.
Adding wrong index to deque.
Incorrect condition to remove out-of-window indices.
✗ Incorrect
Remove smaller elements with '>'; add current index i; remove indices less than window start with '<'.
