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, val): self.val = val self.next = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to 0 or val instead of None.
Confusing next with the node's value.
✗ Incorrect
When creating a new node, its next pointer should initially be None because it doesn't point to any other node yet.
2fill in blank
mediumComplete the code to start merging by creating a dummy node.
DSA Python
def mergeTwoLists(l1, l2): dummy = Node([1]) current = dummy # merging logic follows
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None as a value which causes errors.
Using l1.val which may not exist if l1 is None.
✗ Incorrect
A dummy node with a placeholder value like -1 helps simplify the merge logic without affecting the final list.
3fill in blank
hardFix the error in the while loop condition to merge until one list ends.
DSA Python
while l1 [1] None and l2 != None: if l1.val < l2.val: current.next = l1 l1 = l1.next else: current.next = l2 l2 = l2.next current = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which stops the loop immediately.
Using comparison operators like '<' or '>' which are invalid here.
✗ Incorrect
The loop should continue while both l1 and l2 are not None, so the condition uses '!=' to check they exist.
4fill in blank
hardFill both blanks to attach the remaining nodes after the loop ends.
DSA Python
if l1 [1] None: current.next = l1 else: current.next = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'is' instead of 'is not' in the if condition.
Attaching None instead of the remaining list.
✗ Incorrect
If l1 still has nodes (is not None), attach it; otherwise attach l2.
5fill in blank
hardFill the blanks to return the merged list skipping the dummy node.
DSA Python
def mergeTwoLists(l1, l2): dummy = Node(-1) current = dummy while l1 != None and l2 != None: if l1.val < l2.val: current.next = l1 l1 = l1.next else: current.next = l2 l2 = l2.next current = current.next if l1 is not None: current.next = l1 else: current.next = l2 return [1].[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dummy instead of dummy.next.
Returning current or head which are not defined here.
✗ Incorrect
Return dummy.next to skip the dummy node and get the head of the merged list.