Intersection of Linked List

 Given 2 linked lists which merge at some point. Find the node at which the lists merge.

CodingNinjas
author
2y
Parallel Traversal Approach
  • Calculate the length of both the lists, say len1 and len2
  • Get the absolute difference of the lengths, diff = |len1 – len2|
  • Now traverse the long list from the first node till ...read more
CodingNinjas
author
2y
  • First I suggested the brute force approach in which we check each element of the first linked list with each element of other linked list and then moved on to the better-optimized solution using linke...read more
CodingNinjas
author
2y
Brute Force
  • For each node in the first list, traverse the entire second list
  • Check if any node in the second list coincides with the first list
    • If it does, return that node’s data
    • If it doesn’t, return -1...read more
CodingNinjas
author
2y
Hashing Approach
  • Traverse the first list and store the address/reference to each node in a hash set/map/dictionary.
  • Then check every node in the second list:
    • If the address of the node of the second list...read more
Add answer anonymously...
American Express Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter