Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with given data.
DSA Java
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined in the method.
Using 'value' or 'item' which are not parameters here.
✗ Incorrect
The new node should be created with the given 'data' parameter.
2fill in blank
mediumComplete the code to check if the position is 1 (insert at head).
DSA Java
if (position == [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for position == 0 which is invalid in this context.
Using 'position' variable instead of a number.
✗ Incorrect
Position 1 means insertion at the head of the list.
3fill in blank
hardFix the error in updating the previous pointer of the next node.
DSA Java
if (current.next != null) { current.next.[1] = newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect pointer names like 'previous' or 'prevNode'.
Forgetting to check if current.next is not null.
✗ Incorrect
The correct pointer name to update is 'prev' in a doubly linked list node.
4fill in blank
hardFill both blanks to correctly insert the new node at the given position.
DSA Java
newNode.[1] = current.next; current.next = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of assignments.
Using 'prev' instead of 'next' for newNode pointer.
✗ Incorrect
The new node's next pointer should point to current.next, and current's next should point to newNode.
5fill in blank
hardFill all three blanks to update pointers after insertion.
DSA Java
newNode.[1] = current; if (newNode.next != null) { newNode.next.[2] = [3]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing which node's prev pointer to update.
Using 'current' instead of 'newNode' in the last pointer update.
✗ Incorrect
newNode.prev points to current; newNode.next.prev points back to newNode.
