FastPrepMerge Two Sorted Lists

Merge Two Sorted Lists

Bloomberg LP logoBloomberg LP● EasyFULLTIMENEW GRADPHONE SCREEN
Learn

Problem statement

Merge two nondecreasing singly linked lists list1 and list2 into one nondecreasing list and return its head.

Function

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

Examples

Example 1

list1 = [1,2,4]list2 = [1,3,4]return = [1,1,2,3,4,4]

Repeatedly choose the smaller front node.

Example 2

list1 = []list2 = [0]return = [0]

An empty list contributes no nodes.

Constraints

  • Each list has at most 10^5 nodes.
  • Node values are 32-bit signed integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
  // Write your code here.
}
list1[1,2,4]
list2[1,3,4]
expected[1,1,2,3,4,4]
Checking account…