Bird
0
0
DSA Cprogramming~10 mins

Sliding Window Maximum Using Deque in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A0
B1
C-1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the first index.
Initializing deque with -1 which is invalid index.
2fill in blank
medium

Complete 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'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong removals.
Using '>=' which may remove equal elements unnecessarily.
3fill in blank
hard

Fix 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'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' removes valid indices too early.
Using '>=' or '>' reverses the logic.
4fill in blank
hard

Fill 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'
Afront
Brear
Ci
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using rear instead of front for max index.
Adding wrong index to deque.
5fill in blank
hard

Fill 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'
A>
Bi
C<
Dfront
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.