FastPrepMerge Two Sorted Linked Lists
Problems/Merge Two Sorted Linked Lists

Merge Two Sorted Linked Lists

Capital One logoCapital One● EasyINTERNFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Capital One reports describe a technical interview whose task was combining two sorted linked lists. In an October 2020 intern report from Richmond, it opened a day of technical, case and behavioral interviews. The other is a February 2018 software engineer onsite in McLean.

Neither gives limits. Here each list holds up to 50 values from -100 to 100 in non-decreasing order. Either list may be empty, and equal values all stay in the result. These are our choices.

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

Inputs: list1 and list2, the heads of two linked lists. Either may be empty, and inside each one the values never decrease from node to node.

Output: the head of one list that uses every node of both inputs, repeated values included, with values that again never decrease. If both inputs are empty, the output is empty.

Function

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

Examples

Example 1

list1 = [0,0,5,17]list2 = [2,3,30,31,32]return = [0,0,2,3,5,17,30,31,32]
list1
00517
list2
23303132
return
0023517303132
From list1From list2

Both 0s from list1 are smaller than anything in list2, so they lead. 2 and 3 fit before 5, then 5 and 17 come next. list1 is then used up, so 30, 31 and 32 close the list.

Example 2

list1 = [5]list2 = [5]return = [5,5]
list1
5
list2
5
return
55
From list1From list2

Two nodes hold the same value. Both are kept, so the answer has two 5s.

Example 3

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

list2 has no nodes, so nothing needs weaving and list1 comes back as it is.

Constraints

  • Neither list has more than 50 nodes.
  • -100 <= Node.val <= 100
  • Within each list, every value is at least as large as the value before it.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • 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
  • Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
  • Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions
  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reverse Linked ListThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Detect a Linked-List CycleGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect a Cycle in a Linked ListPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One 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…