Coders Crushby Napplied AI
Back to DSA Problems
HardHeap / Priority Queue

Merge k Sorted Lists

Merge k sorted linked lists

Solution Approach

Divide problem into subproblems, solve each recursively, combine results. Classic examples: merge sort, quick sort, binary tree problems.

Implementation
def mergeSort(arr):
    if len(arr) <= 1:
        return arr
    mid = len(arr) // 2
    left = mergeSort(arr[:mid])
    right = mergeSort(arr[mid:])
    return merge(left, right)

def merge(left, right):
    result = []
    i = j = 0
    while i < len(left) and j < len(right):
        if left[i] <= right[j]:
            result.append(left[i])
            i += 1
        else:
            result.append(right[j])
            j += 1
    return result + left[i:] + right[j:]
Complexity Analysis

Time Complexity

O(n log n)

Space Complexity

O(n)
Key Learning Points
Divide into subproblemsRecursive solutionCombine subresults
Related Problems to Practice
Merge SortQuick SortInvert Binary Tree
Complexity
Time:O(n log n)
Space:O(n)
Asked at
GoogleAmazonMicrosoft
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless