Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

69. Merge Two Sorted Lists

EasyDay 21 of 60Linked List

You are given the heads of two sorted linked lists, list1 and list2. Merge them into one sorted list by splicing together their existing nodes, and return the head of the merged list.

Example 1
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
Example 2
Input: list1 = [], list2 = [0]
Output: [0]
Constraints
  • Each list has 0 to 50 nodes
  • -100 <= Node.val <= 100
  • Both lists are sorted in non-decreasing order
Hints
Frequently asked at: Amazon, Microsoft, Apple, Accenture, Cognizant
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min