Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the linked list is empty before starting the loop.
DSA Java
if (head == [1]) { return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head equals head (always true).
Using tail instead of head.
✗ Incorrect
We check if head is null to know if the list is empty. If it is, it cannot be circular.
2fill in blank
mediumComplete the code to move the slow pointer one step forward.
DSA Java
slow = slow.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using prev which points backward.
Using head or tail which are not node pointers.
✗ Incorrect
To move forward in a linked list, we use the next pointer.
3fill in blank
hardFix the error in the while loop condition to avoid null pointer exceptions.
DSA Java
while (fast != null && fast.[1] != null) { // loop body }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking fast.prev which does not exist in singly linked list.
Checking fast.head or fast.tail which are invalid.
✗ Incorrect
We check fast.next to ensure fast can move two steps safely.
4fill in blank
hardFill both blanks to move fast pointer two steps ahead safely.
DSA Java
fast = fast.[1]; fast = fast.[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev which is not in singly linked list.
Using head or tail which are not node pointers.
✗ Incorrect
Fast pointer moves two steps by following next twice.
5fill in blank
hardFill all four blanks to complete the circular linked list detection using Floyd's cycle algorithm.
DSA Java
Node slow = head; Node fast = head; while (fast != null && fast.[1] != null) { slow = slow.[2]; fast = fast.[3].[4]; if (slow == fast) { return true; } } return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev pointers which do not exist in singly linked list.
Not checking fast.next before moving fast.
✗ Incorrect
Floyd's cycle detection moves slow by one step and fast by two steps using next pointers.
