Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the same value as the current node.
DSA Python
new_node = Node(current.val[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of parentheses.
Using curly braces {} which are for dictionaries or sets.
✗ Incorrect
To create a new node, we call the Node constructor with parentheses and pass the value.
2fill in blank
mediumComplete the code to link the new node after the current node.
DSA Python
current.next = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current.next to current itself causes a cycle.
Assigning current.next to head or random is incorrect.
✗ Incorrect
We set current.next to new_node to insert the cloned node after current.
3fill in blank
hardFix the error in setting the random pointer of the cloned node.
DSA Python
current.next.random = current.random[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .random instead of .next leads to wrong pointer.
Using .next.next skips one node too far.
✗ Incorrect
The cloned node's random pointer should point to the clone of current.random, which is current.random.next.
4fill in blank
hardFill both blanks to separate the original and cloned lists.
DSA Python
original.next = original.next[1] clone.next = clone.next[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .random instead of .next causes wrong links.
Using .random.next is incorrect for next pointers.
✗ Incorrect
To separate the lists, we skip every other node by assigning next pointers to next.next.
5fill in blank
hardFill all three blanks to complete the clone function.
DSA Python
def cloneLinkedList(head): if not head: return None current = head while current: new_node = Node(current.val[1]) new_node.next = current.next current.next = new_node current = new_node.next current = head while current: if current.random: current.next.random = current.random[2] current = current.next.next original = head clone = head.next clone_head = clone while original: original.next = original.next[3] if clone.next: clone.next = clone.next.next original = original.next clone = clone.next return clone_head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses in constructor call.
Wrong attribute used for random pointer.
Incorrect next pointer update causing cycles.
✗ Incorrect
The blanks fill the constructor call, the random pointer assignment, and the original list next pointer update.