Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Python
class Node: def __init__(self, data): self.data = [1] self.next = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the constructor.
Assigning None instead of the input data.
✗ Incorrect
The constructor assigns the input parameter 'data' to the node's data attribute.
2fill in blank
mediumComplete the code to move the slow pointer one step forward in the linked list.
DSA Python
slow = slow[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Moving two steps instead of one.
Trying to access a non-existent 'prev' attribute.
✗ Incorrect
To move one step forward, we use slow.next.
3fill in blank
hardFix the error in the while loop condition to correctly check if fast and fast.next exist.
DSA Python
while fast is not None and fast[1] is not None: slow = slow.next fast = fast.next.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking fast.next.next instead of fast.next.
Checking fast.prev which does not exist.
✗ Incorrect
We must check if fast.next is not None before moving fast two steps.
4fill in blank
hardFill both blanks to create a function that returns the middle node's data.
DSA Python
def find_middle(head): slow = head fast = head while fast is not None and fast[1] is not None: slow = slow[2] fast = fast.next.next return slow.data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which does not exist.
Moving slow two steps instead of one.
✗ Incorrect
We check fast.next and move slow one step with slow.next.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps nodes to their data if data is even.
DSA Python
result = [1]: [2] for node in nodes if node.data [3] 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '% 2 =='.
Swapping key and value in the dictionary.
✗ Incorrect
We map node to node.data and check if node.data % 2 == 0 for even data.