0
0
DSA Pythonprogramming~10 mins

Add Two Numbers Represented as Linked List in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new node with the sum digit.

DSA Python
new_node = ListNode([1])
Drag options to blanks, or click blank then click option'
Asum % 10
Bsum + 10
Csum // 10
Dsum * 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum // 10 instead of sum % 10
Adding 10 to sum instead of modulo
Multiplying sum by 10
2fill in blank
medium

Complete the code to update the carry after adding two digits.

DSA Python
carry = [1]
Drag options to blanks, or click blank then click option'
Asum // 10
Bsum % 10
Csum + 1
Dsum - 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using modulo instead of integer division
Adding 1 to sum instead of dividing
Subtracting 10 from sum
3fill in blank
hard

Fix the error in the loop condition to continue while nodes or carry exist.

DSA Python
while l1 or l2 or [1]:
Drag options to blanks, or click blank then click option'
Anew_node
Bsum
CNone
Dcarry
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum which is undefined here
Using new_node which is a node, not a condition
Using None which stops the loop
4fill in blank
hard

Fill both blanks to correctly move to the next nodes in the lists.

DSA Python
l1 = l1[1] if l1 else None
l2 = l2[2] if l2 else None
Drag options to blanks, or click blank then click option'
A.next
B.prev
C.head
D.tail
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is for doubly linked lists backwards
Using .head or .tail which are not node pointers
5fill in blank
hard

Fill both blanks to initialize the dummy node, set current pointer, and return the result list.

DSA Python
dummy = ListNode([1])
current = dummy
...
return dummy[2]
Drag options to blanks, or click blank then click option'
A0
B.next
C.prev
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dummy instead of dummy.next
Using None instead of 0 for dummy node value
Using .prev which is not correct here