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 'node' or 'head' instead of the value.
Passing null instead of the value.
✗ Incorrect
We create a new node using the given value to insert at the end.
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 circle.
Using head which is null in this case.
✗ Incorrect
In a circular linked list with one node, the node points to itself.
3fill in blank
hardFix the error in the loop condition to find the last node in the circular list.
DSA Typescript
let current = head; while (current.next [1] head) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes the loop to stop immediately.
Using '<' or '>' is invalid for node comparison.
✗ Incorrect
We loop until current.next points back to head, so we check for inequality.
4fill in blank
hardFill both blanks to insert newNode at the end and maintain circular links.
DSA Typescript
current.next = [1]; newNode.next = [2]; return head;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode.next to current breaks the circle.
Setting current.next to head instead of newNode.
✗ Incorrect
The last node points to newNode, and newNode points back to head to keep the circle.
5fill in blank
hardFill all three blanks to complete the insertAtEnd function for a circular linked list.
DSA Typescript
function insertAtEnd(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] head) {
current = current.next;
}
current.next = newNode;
newNode.next = head;
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' or 'null' instead of 'value' when creating newNode.
Setting newNode.next to head in empty list case.
Using '==' instead of '!=' in loop condition.
✗ Incorrect
We create newNode with value, point newNode.next to itself if list is empty, and loop while current.next is not head.
