Bird
0
0
DSA Cprogramming~20 mins

Intersection Point of Two Linked Lists in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Intersection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Find the intersection node value
Given two singly linked lists that intersect, what is the value of the node where they intersect?
DSA C
struct Node {
    int data;
    struct Node* next;
};

// List A: 1 -> 2 -> 3 -> 4 -> 5 -> NULL
// List B: 9 -> 4 -> 5 -> NULL (4 and 5 are shared nodes)

// Intersection at node with value 4

int getIntersectionNode(struct Node* headA, struct Node* headB) {
    struct Node *a = headA, *b = headB;
    while (a != b) {
        a = (a == NULL) ? headB : a->next;
        b = (b == NULL) ? headA : b->next;
    }
    return a ? a->data : -1;
}
A3
B5
C4
D-1
Attempts:
2 left
💡 Hint
Think about how pointers move through both lists and meet at the intersection.
Predict Output
intermediate
2:00remaining
Output of intersection detection with no intersection
What is the output of the function when two linked lists do not intersect?
DSA C
struct Node {
    int data;
    struct Node* next;
};

int getIntersectionNode(struct Node* headA, struct Node* headB) {
    struct Node *a = headA, *b = headB;
    while (a != b) {
        a = (a == NULL) ? headB : a->next;
        b = (b == NULL) ? headA : b->next;
    }
    return a ? a->data : -1;
}

// List A: 1 -> 2 -> 3 -> NULL
// List B: 4 -> 5 -> 6 -> NULL
// No intersection
A0
B6
C3
D-1
Attempts:
2 left
💡 Hint
If no intersection exists, the pointers will both become NULL at the same time.
🧠 Conceptual
advanced
2:00remaining
Why does the two-pointer technique work for intersection detection?
Why does moving two pointers through both lists and switching heads when reaching NULL guarantee they meet at the intersection node?
ABecause both pointers traverse the same total length, so they align at the intersection after switching lists.
BBecause the pointers move at different speeds, causing them to meet at the intersection.
CBecause the pointers use hashing to detect the intersection node.
DBecause the pointers compare node values to find the intersection.
Attempts:
2 left
💡 Hint
Think about the total distance each pointer travels.
🔧 Debug
advanced
2:00remaining
Identify the bug in intersection detection code
What is the bug in this code snippet for detecting intersection of two linked lists?
DSA C
int getIntersectionNode(struct Node* headA, struct Node* headB) {
    struct Node *a = headA, *b = headB;
    while (a != NULL && b != NULL) {
        if (a == b) return a->data;
        a = a->next;
        b = b->next;
    }
    return -1;
}
AThe loop stops too early; it should continue until both pointers are NULL or equal.
BThe pointers should move two steps at a time to detect intersection faster.
CThe function should compare node data instead of node addresses.
DThe function should return 0 instead of -1 when no intersection.
Attempts:
2 left
💡 Hint
Think about what happens if lists have different lengths.
🚀 Application
expert
2:00remaining
Number of nodes in intersection part
Given two intersecting singly linked lists, how many nodes are in the shared intersection part if the first intersection node has value 7 and the lists end at node with value 10?
DSA C
// List A: 3 -> 6 -> 9 -> 7 -> 8 -> 10 -> NULL
// List B: 1 -> 7 -> 8 -> 10 -> NULL
// Intersection starts at node with value 7

// Question: How many nodes are shared from intersection to end?
A2
B3
C4
D5
Attempts:
2 left
💡 Hint
Count nodes starting from the intersection node to the end.