Perhaps the most counter-intuitive heap problem I’ve done so far.
Description
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
nums1
nums2
k
A very intricate usage of heap.
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle…
An extension of Merge Two Sorted Lists. Use heap to keep next pair (val, index) at the top. Shift head to next of target list for directly getting target node in future round.
heapq api in python makes this problem trivial.
Use partial sorting to outperform O(nlogn).