391. Merge Two Sorted Lists — Recursive Approach

MediumLinked ListRecursionMergeLinked List

Given the heads of two sorted linked lists, merge them into one sorted list using a recursive approach and return the merged list as an array. Input: '[l1], [l2]'.

Input: '[l1], [l2]'.

Output: Array — the merged sorted list.

Examples

Example 1
Input: [1,3,5], [2,4,6]
Output: [1,2,3,4,5,6]
Explanation: Interleaved in sorted order.
Example 2
Input: [], [1,2]
Output: [1,2]
Explanation: One list empty.
Example 3
Input: [1], []
Output: [1]
Explanation: Other list empty.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →