Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with given data.
DSA Javascript
class Node { constructor(data) { this.data = [1]; this.next = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of 'data' for the node's data property.
Assigning null to data instead of the input parameter.
✗ Incorrect
The constructor assigns the input data to the node's data property.
2fill in blank
mediumComplete the code to check if the list is empty before deletion.
DSA Javascript
function deleteNode(head, key) {
if (head == [1]) {
return null;
}
// rest of deletion logic
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking head against undefined instead of null.
Using 0 or false which are not valid for empty list check.
✗ Incorrect
An empty list is represented by head being null.
3fill in blank
hardFix the error in the loop condition to find the node before the one to delete.
DSA Javascript
let current = head;
do {
if (current.next.data === key) {
break;
}
current = current[1];
} while (current !== head);Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is not defined in singly circular linked list.
Using .data or .head which are not pointers to next node.
✗ Incorrect
To move to the next node, use current.next.
4fill in blank
hardFill both blanks to update the links when deleting the head node.
DSA Javascript
if (current.next === head) { head = head[1]; current[2] = head; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which does not exist in singly linked list.
Using .data or .head which are not pointers.
✗ Incorrect
To delete head, move head to next node and update last node's next to new head.
5fill in blank
hardFill all three blanks to delete a node with given key from circular linked list.
DSA Javascript
function deleteNode(head, key) {
if (head == null) return null;
let current = head;
let prev = null;
do {
if (current.data === [1]) {
if (prev != null) {
prev[2] = current[3];
} else {
// handle head deletion
}
break;
}
prev = current;
current = current.next;
} while (current !== head);
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using prev.prev or current.prev which do not exist.
Using head or other variables incorrectly in link update.
✗ Incorrect
Check if current.data equals key, then set prev.next to current.next to remove current node.
