0
0
DSA Pythonprogramming~10 mins

Intersection Point of Two Linked Lists 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 return the node where two linked lists intersect.

DSA Python
def getIntersectionNode(headA, headB):
    while headA and headB and headA != headB:
        headA = headA.next
        headB = headB.next
    return [1]
Drag options to blanks, or click blank then click option'
AheadA.next
BheadA
CheadB
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Returning headB instead of headA
Returning None prematurely
Returning headA.next which may be None
2fill in blank
medium

Complete the code to switch the pointer to the other list when it reaches the end.

DSA Python
def getIntersectionNode(headA, headB):
    a, b = headA, headB
    while a != b:
        a = a.next if a else [1]
        b = b.next if b else headA
    return a
Drag options to blanks, or click blank then click option'
ANone
BheadA
CheadB
Da
Attempts:
3 left
💡 Hint
Common Mistakes
Switching to headA instead of headB
Not switching pointer at all
Using None instead of headB
3fill in blank
hard

Fix the error in the loop condition to correctly detect intersection.

DSA Python
def getIntersectionNode(headA, headB):
    a, b = headA, headB
    while [1]:
        a = a.next if a else headB
        b = b.next if b else headA
    return a
Drag options to blanks, or click blank then click option'
Aa != b
Ba or b
Ca and b
Da == b
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality in the loop condition
Using logical and/or incorrectly
Infinite loop due to wrong condition
4fill in blank
hard

Fill both blanks to create a loop that moves pointers or switches lists.

DSA Python
def getIntersectionNode(headA, headB):
    a, b = headA, headB
    while a != b:
        a = a[1] if a else [2]
        b = b.next if b else headA
    return a
Drag options to blanks, or click blank then click option'
A.next
BheadB
CheadA
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute instead of .next
Switching to headA instead of headB
Using None instead of list head
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering nodes by value.

DSA Python
def filterNodes(nodes):
    return [1]: [2] for node in nodes if node.val [3] 10
Drag options to blanks, or click blank then click option'
Anode.val
Bnode
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using node instead of node.val as key
Using wrong comparison operator
Not filtering nodes correctly