Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the list is empty or has one node.
DSA C
if (head == NULL || head->[1] == NULL) { return head; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' in a singly linked list.
Checking the data value instead of the next pointer.
✗ Incorrect
The base case for recursion checks if the list is empty or has only one node by checking if head or head->next is NULL.
2fill in blank
mediumComplete the code to recursively reverse the rest of the list.
DSA C
struct Node* rest = [1](head->next); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function that frees or deletes the list instead of reversing.
Calling a print function instead of recursive reverse.
✗ Incorrect
The function calls itself recursively to reverse the rest of the list starting from head->next.
3fill in blank
hardFix the error in setting the next node's next pointer to the current head.
DSA C
head->next->[1] = head; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which does not exist in singly linked list nodes.
Trying to assign to data or value fields.
✗ Incorrect
To reverse the link, set head->next->next to head, changing the direction of the pointer.
4fill in blank
hardFill both blanks to complete the recursive reversal and break the old link.
DSA C
head->[1] = NULL; return [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning head instead of rest.
Not setting head->next to NULL causing cycles.
✗ Incorrect
After reversing, set head->next to NULL to break the old link and return the new head stored in rest.
5fill in blank
hardFill all three blanks to complete the full recursive reverse function.
DSA C
struct Node* reverseList(struct Node* head) {
if (head == NULL || head->[1] == NULL) {
return head;
}
struct Node* [2] = reverseList(head->next);
head->next->[3] = head;
head->next = NULL;
return [2];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is not part of singly linked list node.
Not breaking the old link by setting head->next to NULL.
✗ Incorrect
The function checks if head or head->next is NULL, recursively reverses the rest, sets head->next->next to head, breaks old link, and returns new head.
