Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Typescript
const newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' or 'node' instead of the value to create the new node.
Passing null instead of the value.
✗ Incorrect
We create a new node using the given value to insert at the beginning.
2fill in blank
mediumComplete the code to handle the empty list case by pointing newNode.next to itself.
DSA Typescript
if (!head) { newNode.next = [1]; return newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to null or undefined breaks the circular property.
Using head which is null in this case.
✗ Incorrect
For an empty circular list, the new node points to itself to form a single-node circle.
3fill in blank
hardFix the error in the loop that finds the last node in the circular list.
DSA Typescript
let current = head; while (current.next !== [1]) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for null or undefined which never occurs in circular lists.
Using newNode which is not yet linked.
✗ Incorrect
The last node points back to head in a circular linked list, so we loop until current.next is head.
4fill in blank
hardFill both blanks to insert newNode at the beginning and update the last node's next pointer.
DSA Typescript
current.next = [1]; newNode.next = [2]; return newNode;
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the pointers incorrectly.
Setting next to null which breaks circularity.
✗ Incorrect
The last node's next points to newNode, and newNode's next points to the old head to insert at beginning.
5fill in blank
hardFill all three blanks to complete the insertAtBeginning function for a circular linked list.
DSA Typescript
function insertAtBeginning(head: Node | null, value: number): Node {
const newNode = new Node([1]);
if (!head) {
newNode.next = [2];
return newNode;
}
let current = head;
while (current.next !== [3]) {
current = current.next;
}
current.next = newNode;
newNode.next = head;
return newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up pointers causing broken circular links.
Not handling empty list correctly.
✗ Incorrect
Create newNode with value, point newNode.next to itself if list empty, loop until current.next is head to find last node.
