Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element at the front of the dequeue.
DSA Java
deque.[1](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using addLast instead of addFirst adds element at the end, not front.
Using remove methods instead of add methods.
✗ Incorrect
The method addFirst adds an element at the front of the dequeue.
2fill in blank
mediumComplete the code to remove an element from the rear of the dequeue.
DSA Java
int removed = deque.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using removeFirst removes from front, not rear.
Using add methods instead of remove methods.
✗ Incorrect
The method removeLast removes and returns the element from the rear of the dequeue.
3fill in blank
hardFix the error in the code to peek at the front element without removing it.
DSA Java
int front = deque.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using poll methods removes the element.
Using peekLast looks at the rear, not front.
✗ Incorrect
peekFirst returns the front element without removing it. pollFirst removes it.
4fill in blank
hardFill both blanks to add 20 at the rear and remove from the front.
DSA Java
deque.[1](20); int removed = deque.[2]();
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing addFirst with removeFirst or addLast with removeLast incorrectly.
Using removeLast instead of removeFirst.
✗ Incorrect
addLast adds at rear, removeFirst removes from front.
5fill in blank
hardFill all three blanks to add 5 at front, 15 at rear, and then remove from rear.
DSA Java
deque.[1](5); deque.[2](15); int removed = deque.[3]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using removeFirst instead of removeLast for rear removal.
Mixing addFirst and addLast positions.
✗ Incorrect
addFirst adds at front, addLast adds at rear, removeLast removes from rear.
