Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Merge sorted lists and LRU cache.



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Merge Multiple Sorted Linked Lists

Merge Multiple Sorted Linked Lists

Problem Statement

Given several sorted linked lists, combine all of them into one sorted linked list and return the merged list. Consider the efficiency of your solution.

Examples

Input:
[
  2->5->7,
  2->4->6,
  3->8
]
Output: 2->2->3->4->5->6->7->8
  
Input:
[
  1->3->4,
  1->2->5,
  4->6
]
Output: 1->1->2->3->4->4->5->6
  

Constraints

  • The number of linked lists will be between 1 and 25.
  • Each linked list will contain between 0 and 600 nodes.
  • Values of nodes are in the range -10,000 to 10,000.