HARD Faang Interview Question - Merge K Sorted Linked Lists - Leetcode 23

preview_player
Показать описание
HARD Faang Interview Question - Merge K Sorted Linked Lists - Leetcode 23

#coding #leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

I've never in my 20 years as a professional developer even used a linked list.

JP-hrxq
Автор

I used Divide and Conquer when I solved this, and thanks to lists nature it runs with O(1) Space Complexity. Have to try the heap approach, it seems faster on average time.

Phrozends
Автор

Algorithm:

Create a heap where each element is a linked list, and the priority key for each node is the smallest value of the linked list

Pop the smallest list off the heap

Pop the first element off of that linked list, and add it to our solution list. Push the rest of the list back onto the heap

Repeat until the heap is empty

austinglander
Автор

I can't follow the explanation it is to hard to mentalize

guilhemgmescudi
Автор

wont it be easier to go through each linked list and push all of their values into the heap instead of the entire list?

Tita.n
welcome to shbcf.ru