Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start traversing the linked list from the head node.
DSA Javascript
function searchLinkedList(head, target) {
let current = [1];
while (current !== null) {
if (current.value === target) {
return true;
}
current = current.next;
}
return false;
}Attempts:
3 left
💡 Hint
Common Mistakes
Initializing current to 'tail' instead of 'head'.
Initializing current to 'null' which stops traversal immediately.
✗ Incorrect
We start traversing the linked list from the head node, so 'current' should be initialized to 'head'.
2fill in blank
mediumComplete the condition to check if the current node's value matches the target.
DSA Javascript
if (current.[1] === target) { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing current.next to target instead of current.value.
Using 'head' or 'target' as a property which does not exist on the node.
✗ Incorrect
Each node stores its data in the 'value' property, so we compare current.value with the target.
3fill in blank
hardFix the error in updating the current node to the next node during traversal.
DSA Javascript
current = current.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current to current.value which is data, not a node.
Assigning current to current.head which is undefined.
✗ Incorrect
To move to the next node, we assign current to current.next.
4fill in blank
hardFill both blanks to complete the while loop condition and the return value when the target is not found.
DSA Javascript
while (current [1] null) { if (current.value === target) { return true; } current = current.next; } return [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' in the while condition.
Returning true when the target is not found.
✗ Incorrect
The loop continues while current is not null, and if the target is not found, the function returns false.
5fill in blank
hardFill all three blanks to create a function that searches for a value in a linked list and returns true if found, false otherwise.
DSA Javascript
function searchList([1], target) { let current = [2]; while (current !== null) { if (current.[3] === target) { return true; } current = current.next; } return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' as the parameter name instead of 'head'.
Comparing current.next to target instead of current.value.
✗ Incorrect
The function takes 'head' as input, starts traversal from 'head', and compares 'current.value' to the target.
