FastPrepFind Where Two Linked Lists Merge
Problems/Find Where Two Linked Lists Merge

Find Where Two Linked Lists Merge

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Expedia intern write-ups ask about two singly linked lists that join. A post from 2019, about campus hiring for the 2020 internship, says the second technical interview asked whether two lists join at some node. The author first kept one list's nodes in a set. Then they were asked to use less memory, and switched to lining the lists up by how much longer one is. An anonymous entry about a campus process in September 2022 lists the task as the second problem of the first video call. Its title points to a problem about values found in two sorted lists. But the candidate's own text describes two lists joining at a node and asks for that node's value, or -1 if they never join. That reading is used here.

Neither gives examples or limits. Here, both lists live in one table of numbered nodes. You return the number of the first shared node, or -1, rather than a stored value or a yes or no answer. The table has 1 to 2000 nodes, and both lists end without a loop.

Our version is about 80% the same as the reported questions.

Two singly linked lists are stored in one node table. The nodes are numbered 0 to n - 1. next[i] is the number of the node that comes after node i, or -1 if node i is the last node of its list. headA and headB are the first nodes of list A and list B.

The two lists may merge: from some node on, they use the same nodes all the way to the end. Return the number of the first node that is on both lists. If the lists share no node, return -1.

Two nodes are the same only if they have the same number. Table entries for nodes that neither list reaches do not change the answer.

Function

findMergeNode(next: int[], headA: int, headB: int) → int

Examples

Example 1

next = [1,2,3,-1,5,2]headA = 0headB = 4return = 2

List A is 0 -> 1 -> 2 -> 3 and list B is 4 -> 5 -> 2 -> 3. Both lists reach node 2 and share every node after it, so the answer is 2.

Example 2

next = [1,-1,3,-1]headA = 0headB = 2return = -1

List A is 0 -> 1 and list B is 2 -> 3. They have no node in common, so the answer is -1.

Example 3

next = [1,2,-1]headA = 0headB = 1return = 1

List A is 0 -> 1 -> 2 and list B is 1 -> 2. List B starts on a node of list A, so the first shared node is B's own head, 1.

Constraints

  • 1 <= n <= 2000, where n is the length of next.
  • -1 <= next[i] <= 1999
  • 0 <= headA, headB <= 1999
  • Both heads, and every next[i] that is not -1, are less than n.
  • Following next from headA or from headB reaches -1 without visiting any node twice.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Detect a Linked-List CyclePaytm · ONSITE INTERVIEWPaytm interview questions
  • Detect a Linked-List CycleCapgemini · ONSITE INTERVIEWCapgemini interview questions
  • Detect a Linked-List CycleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Detect and Remove a Linked List LoopBank of America · ONSITE INTERVIEWBank of America interview questions
  • First Node Two Linked Lists ShareAdobe · PHONE SCREENAdobe interview questions
  • Where Two Linked Lists MeetNutanix · PHONE SCREENNutanix interview questions
  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int findMergeNode(int[] next, int headA, int headB) {
        // Write your code here.
    }
}
Checking account…