Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a pointer to traverse the linked list.
DSA C++
Node* [1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fast' or 'slow' pointer names before initializing them.
Using 'middle' as a pointer name at this stage.
✗ Incorrect
We use a temporary pointer named 'temp' to traverse the linked list from the head.
2fill in blank
mediumComplete the code to move the slow pointer one step forward in the linked list.
DSA C++
slow = slow[1]next;Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' to access pointer members.
Using '*' which dereferences but does not access members.
✗ Incorrect
To access the next node through a pointer, we use the '->' operator.
3fill in blank
hardFix the error in the loop condition to ensure fast pointer and its next are not null.
DSA C++
while (fast != nullptr && fast[1]next != nullptr) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' causing compilation errors.
Using '*' which is incorrect here.
✗ Incorrect
We use '->' to access the 'next' member of the pointer 'fast'.
4fill in blank
hardFill both blanks to move slow pointer one step and fast pointer two steps forward.
DSA C++
slow = slow[1]next; fast = fast[2]next[3]next;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' causing errors.
Moving fast pointer only one step.
✗ Incorrect
Use '->' to access members of pointers. Slow moves one step: slow->next. Fast moves two steps: fast->next->next.
5fill in blank
hardFill all three blanks to return the data of the middle node after traversal.
DSA C++
int findMiddle(Node* head) {
Node* slow = head;
Node* fast = head;
while (fast != nullptr && fast[1]next != nullptr) {
slow = slow[2]next;
fast = fast[3]next->next;
}
return slow->data;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' causing compilation errors.
Incorrectly moving pointers causing infinite loops.
✗ Incorrect
All pointer member accesses use '->'. The loop checks fast->next, slow moves slow->next, fast moves fast->next->next.
