Skip to interview prep
Apexed

15. Merge Two Sorted Lists

EasyLinked lists

Merge two sorted linked lists into one sorted list and return its head.

A linked list is passed as ListNode objects with val and next. The tests write lists as arrays.

Example 1

Input: a = [1, 2, 4], b = [1, 3, 4]
Output: [1, 1, 2, 3, 4, 4]

Constraints

  • 0 ≤ nodes in each list ≤ 50

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Merge Two Sorted Lists — coding interview practice — Apexed