Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Solution: Merge Two Sorted Lists

Problem Statement

Given the head of two sorted linked lists, l1 and l2.

Return a new sorted list created by merging together the nodes of the first two lists.

Examples

  1. Example 1:

    • Input:
      [1, 3, 5]
      [2, 4, 6]
      
    • Expected Output:
      [1, 2, 3, 4, 5, 6]
      
    • Justification: Merging the two sorted linked lists, node by node, results in a single sorted linked list containing all elements from both input lists.
  2. Example 2:

    • Input:
      [2, 4, 6]
      [1, 3, 5]
      

.....

.....

.....

Like the course? Get enrolled and start learning!