Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the next node in the linked list.
DSA C
current = current->[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to move forward.
Using 'head' or 'tail' which are not pointers of the current node.
✗ Incorrect
In a singly linked list, the pointer to the next node is accessed using 'next'.
2fill in blank
mediumComplete the code to find the middle node of the linked list using slow and fast pointers.
DSA C
while (fast != NULL && fast->[1] != NULL) { slow = slow->next; fast = fast->next->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for fast pointer movement.
Not checking if fast->next is NULL before accessing fast->next->next.
✗ Incorrect
The fast pointer moves two steps ahead using 'next' pointers to find the middle.
3fill in blank
hardFix the error in the code to reverse the second half of the linked list.
DSA C
struct ListNode* prev = NULL; struct ListNode* curr = head; while (curr != NULL) { struct ListNode* nextTemp = curr->[1]; curr->next = prev; prev = curr; curr = nextTemp; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to save the next node.
Not saving the next node before reversing the link.
✗ Incorrect
To reverse the list, we must store the next node using 'next' pointer before changing links.
4fill in blank
hardFill both blanks to merge two halves of the linked list alternately.
DSA C
while (second != NULL) { struct ListNode* temp1 = first->next; struct ListNode* temp2 = second->[1]; first->next = second; second->next = temp1; first = temp1; second = [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to move forward.
Assigning wrong variable to 'second' causing infinite loop.
✗ Incorrect
We use 'next' to move forward in the second list and assign 'temp2' to second for next iteration.
5fill in blank
hardFill all three blanks to complete the reorder list function.
DSA C
void reorderList(struct ListNode* head) {
if (head == NULL || head->next == NULL) return;
struct ListNode *slow = head, *fast = head;
while (fast != NULL && fast->next != NULL) {
slow = slow->next;
fast = fast->next->[1];
}
struct ListNode* second = slow->next;
slow->next = NULL;
struct ListNode* prev = NULL;
struct ListNode* curr = second;
while (curr != NULL) {
struct ListNode* nextTemp = curr->[2];
curr->next = prev;
prev = curr;
curr = nextTemp;
}
struct ListNode* first = head;
second = prev;
while (second != NULL) {
struct ListNode* temp1 = first->next;
struct ListNode* temp2 = second->next;
first->next = second;
second->next = temp1;
first = temp1;
second = [3];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for fast pointer movement.
Not saving 'next' before reversing links.
Assigning wrong variable to 'second' in merge loop.
✗ Incorrect
Fast pointer moves two steps using 'next', reversing uses 'next', and 'second' moves to 'temp2' to merge.
