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.
Forgetting to pass any argument.
✗ Incorrect
We create a new node by passing the value to the Node constructor.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA Typescript
newNode.[1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'head' instead of 'next'.
Using 'prev' which is for doubly linked lists.
✗ Incorrect
The 'next' pointer of the new node should point to the current head.
3fill in blank
hardFix the error in updating the head pointer to the new node.
DSA Typescript
head = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to newNode.next which skips the new node.
Assigning head to null which empties the list.
✗ Incorrect
The head must point to the new node after insertion.
4fill in blank
hardFill both blanks to complete the push function that inserts a new node at the front.
DSA Typescript
function push(value: number) {
const newNode = new Node([1]);
newNode.[2] = head;
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next'.
Not linking the new node to the existing list.
✗ Incorrect
We create a new node with the value and link its next to the current head.
5fill in blank
hardFill all three blanks to complete the push function with proper node creation, linking, and head update.
DSA Typescript
function push(value: number) {
const newNode = new Node([1]);
newNode.[2] = [3];
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next'.
Not updating head correctly.
✗ Incorrect
Create a new node with value, link its next to head, then update head to newNode.
