FastPrepMerge Two Sorted Lists
Problems/Merge Two Sorted Lists

Merge Two Sorted Lists

LinkedIn logoLinkedIn● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a LinkedIn phone screen for an experienced machine learning engineer role, where the official title was software engineer. The coding question was the well-known task of merging two sorted linked lists into one sorted list. The report names the question only and gives no examples or limits.

Here, each list has at most 50 nodes with values from -100 to 100, and the examples are our own.

Our version is about 95% the same as the reported question.

Two singly linked lists, list1 and list2, are each sorted in non-decreasing order. Combine all of their nodes into a single list that is also in non-decreasing order, and return the head of that list.

Build the result by relinking the existing nodes, not by creating new ones. Every node of both inputs must appear exactly once, including nodes with equal values. If both inputs are empty, return an empty list.

Function

mergeTwoLists(list1: ListNode, list2: ListNode) → ListNode

Examples

Example 1

list1 = [2,5,9]list2 = [1,5,6,12]return = [1,2,5,5,6,9,12]
list1
259
list2
15612
return
12556912
From list1From list2
  • Compare the fronts 2 and 1: take 1 from list2. Then 2 from list1.
  • Both fronts are 5. Take either one, then the other, so both copies of 5 stay in the result.
  • Next come 6, then 9. Now list1 is used up, so the rest of list2, which is 12, goes at the end.

Example 2

list1 = []list2 = [3,4]return = [3,4]
list1
empty
list2
34
→
return
34

list1 is empty, so the merged list is just list2.

Example 3

list1 = [-3,-3,8]list2 = [-3,10]return = [-3,-3,-3,8,10]
list1
-3-38
list2
-310
return
-3-3-3810
From list1From list2

All three nodes with value -3 come first. Then 8 from list1 and 10 from list2 follow in order.

Constraints

  • Each list has between 0 and 50 nodes.
  • -100 <= Node.val <= 100
  • In each list, the values never decrease from head to tail.

More LinkedIn Phone Screen questions

  • Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Sqrt(x)PHONE SCREEN · Seen Nov 2026
  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
  • Known Words Matching Phone DigitsPHONE SCREEN · Seen Oct 2026
  • Inverse-Depth Nested List SumPHONE SCREEN · Seen Oct 2026
  • Valid Number with ExponentsPHONE SCREEN · Seen Oct 2026
  • Sort a Quadratic-Transformed ArrayPHONE SCREEN · Seen Oct 2026
  • Constant-Time Minimum StackPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Merge Two Sorted ListsThe Walt Disney Company · OAThe Walt Disney Company interview questions
  • Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
  • Reverse a Linked ListApple · PHONE SCREENApple interview questions
  • Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
  • Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
  • Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
  • Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
  • Reverse a Linked ListMygate · PHONE SCREENMygate interview questions

Interview reports that mention this question

  • LinkedIn Senior MLE Interview Questions: 1 Experience

LinkedIn interview experiences

  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        // Write your code here.
    }
}
Checking account…