Summer Sale is Live! Unlock 40% OFF on All Job-Oriented Training Programs – Limited Time Only! Offer Ending in
D
H
M
S
Get Now
Problem Submissions Solution

Intersection of Two Linked Lists

Difficulty: Easy

Acceptance: %

Points: 20.00

Given two linked lists, head1 and head2, identify the intersection of the two lists. Both linked lists have unique node values with no duplicates.

Note: The nodes in the resulting list should maintain the same order as they appear in the input list head1. If there are no common elements between the two lists, return null.



Topics

Companies

Articles

Examples:

Expected Time Complexity: O(m+n)

Expected Space Complexity: O(m+n)

Constraints:
  • 1 <= no. of nodes in head1, head2 <= 10^4
  • 1 <= node->data <= 10^5
Companies:
Amazon Microsoft Visa Flipkart
Topics:
Linked List
Locked Content
Access Restricted: Please Login to access the code editor and test cases.