Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return null if either linked list head is null.
DSA Javascript
function getIntersectionNode(headA, headB) {
if (headA === null || [1] === null) return null;
// rest of the code
}Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for the second list head.
✗ Incorrect
We check if either headA or headB is null to return null early.
2fill in blank
mediumComplete the code to advance pointerA to the next node.
DSA Javascript
pointerA = pointerA[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using arrow notation or calling next as a function.
✗ Incorrect
In JavaScript, to access the next node, use pointerA.next.
3fill in blank
hardFix the error in the while loop condition to continue until pointerA equals pointerB.
DSA Javascript
while (pointerA [1] pointerB) { // loop body }
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment operator instead of comparison.
✗ Incorrect
We want to loop while pointerA is not equal to pointerB, so use !==.
4fill in blank
hardFill both blanks to reset pointerA and pointerB to the other list's head when they reach null.
DSA Javascript
pointerA = pointerA === null ? [1] : pointerA.next; pointerB = pointerB === null ? [2] : pointerB.next;
Attempts:
3 left
💡 Hint
Common Mistakes
Resetting to the same list's head or null.
✗ Incorrect
When pointerA reaches null, reset it to headB; when pointerB reaches null, reset it to headA.
5fill in blank
hardFill all three blanks to return the intersection node or null if none exists.
DSA Javascript
return [1] === [2] ? [3] : null;
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the wrong pointer or head node.
✗ Incorrect
If pointerA equals pointerB, return pointerA (the intersection node), else return null.
