Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move the pointer to the next node.
DSA Typescript
current = current[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to move forward.
Using 'head' or 'tail' which are not properties of a node.
✗ Incorrect
In a linked list, each node points to the next node using the 'next' property.
2fill in blank
mediumComplete the code to check if two nodes are the same (intersection point).
DSA Typescript
if (nodeA[1] nodeB) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' or '!=' which do type coercion.
Using '!==' which checks for inequality.
✗ Incorrect
To find the intersection, we check if the two nodes are exactly the same object using '==='.
3fill in blank
hardFix the error in the loop condition to avoid infinite loop.
DSA Typescript
while (pointerA [1] null && pointerB [1] null) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '===' which stops the loop too early.
Using '||' which causes wrong loop behavior.
✗ Incorrect
We want to continue looping while both pointers are not null, so use '!==' for both comparisons.
4fill in blank
hardFill both blanks to correctly advance pointers or reset them to head.
DSA Typescript
pointerA = pointerA ? pointerA[1] : headB; pointerB = pointerB ? pointerB[2] : headA;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.prev' which moves backward.
Using '.head' or '.tail' which are not node properties.
✗ Incorrect
If the pointer is not null, move to the next node; otherwise, reset to the other list's head.
5fill in blank
hardFill all three blanks to create a function that finds the intersection node.
DSA Typescript
function getIntersectionNode(headA: ListNode | null, headB: ListNode | null): ListNode | null {
let pointerA = headA;
let pointerB = headB;
while (pointerA !== pointerB) {
pointerA = pointerA ? pointerA[1] : [2];
pointerB = pointerB ? pointerB[3] : headA;
}
return pointerA;
}Attempts:
3 left
💡 Hint
Common Mistakes
Resetting pointers to wrong heads.
Using '.prev' which is not valid in singly linked lists.
✗ Incorrect
Move pointers forward with '.next'. When a pointer reaches null, reset it to the head of the other list to align traversal.
