Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a linear linked list node pointing to null.
DSA Javascript
const node = { value: 10, next: [1] };Attempts:
3 left
💡 Hint
Common Mistakes
Using the node itself as next creates a circular list.
Using undefined or 0 does not clearly mark the end.
✗ Incorrect
In a linear linked list, the last node's next pointer is null to indicate the end of the list.
2fill in blank
mediumComplete the code to create a circular linked list node pointing to itself.
DSA Javascript
const node = { value: 20 }; node.next = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to null breaks the circular property.
Using undefined or 0 does not create a loop.
✗ Incorrect
In a circular linked list with one node, the next pointer points back to the node itself.
3fill in blank
hardFix the error in the function that checks if a linked list is circular.
DSA Javascript
function isCircular(head) {
if (!head) return false;
let current = head.next;
while (current !== null && current !== head) {
current = [1];
}
return current === head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using head.next causes infinite loop or wrong traversal.
Assigning current to null ends the loop prematurely.
✗ Incorrect
To traverse the list, we must move current to current.next each step.
4fill in blank
hardFill both blanks to complete the function that adds a node to the end of a circular linked list.
DSA Javascript
function addToCircularList(tail, value) {
const newNode = { value: value, next: [1] };
newNode.next = tail.next;
tail.next = newNode;
return [2];
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode.next to null breaks circularity.
Returning old tail instead of newNode loses the updated tail.
✗ Incorrect
The new node's next points to the head (tail.next), and the new node becomes the new tail.
5fill in blank
hardFill all three blanks to complete the function that prints values of a circular linked list starting from head.
DSA Javascript
function printCircularList(head) {
if (!head) return;
let current = head;
do {
console.log(current.[1]);
current = current.[2];
} while (current !== [3]);
}Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next causes errors.
Comparing current to null breaks the loop in circular list.
✗ Incorrect
We print current.value, move to current.next, and stop when we reach head again.
