Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the last node in the linked list.
DSA Javascript
while (current.next [1] null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' causes the loop to stop immediately.
Using '=' causes assignment instead of comparison.
✗ Incorrect
We use '!== null' to continue moving until the last node whose next is null.
2fill in blank
mediumComplete the code to delete the last node by setting the second last node's next to null.
DSA Javascript
secondLast.next [1] null;Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' causes a comparison, not assignment.
Using '=>' is invalid syntax here.
✗ Incorrect
We assign null to secondLast.next to remove the last node.
3fill in blank
hardFix the error in the loop condition to find the second last node.
DSA Javascript
while (current.next.next [1] null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes the loop to stop too early.
Using '=' causes assignment error.
✗ Incorrect
We check that current.next.next is not null to stop at second last node.
4fill in blank
hardFill both blanks to correctly find the second last node and delete the last node.
DSA Javascript
while (current.next [1] null && current.next.next [2] null) { current = current.next; } current.next = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' in either condition causes errors or wrong node deletion.
Using '===' is too strict and may cause unexpected behavior.
✗ Incorrect
Both conditions check for not equal to null to find second last node safely.
5fill in blank
hardFill all three blanks to delete the last node from a singly linked list safely.
DSA Javascript
if (head == null) return null; if (head.next == null) { head = null; return head; } let current = head; while (current.next [1] null && current.next.next [2] null) { current = current.next; } current.next [3] null; return head;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' causes wrong loop behavior.
Using '===' may cause strict comparison issues.
Using '==' or '===' instead of '=' for assignment causes errors.
✗ Incorrect
Use '!==' to check nodes exist and '=' to remove last node by setting next to null.
