All problems
Pairing Heap Merge Lite
Problem
Merge two pairing heaps in one step.
A pairing heap is represented as a nested list: [root_value, child1, child2, ...] where each child is itself a heap. Merging compares the two roots and makes the larger root the first child of the smaller one; ties keep the first heap as the root. None represents an empty heap.
Return the merged heap.
Hint
Only the two roots are compared; the loser becomes the new first child of the winner.
Test cases
case 1
in: [[1,[3],[4]],[2,[5]]]
expected: [1,[2,[5]],[3],[4]]
case 2
in: [[5],[3,[1]]]
expected: [3,[5],[1]]
case 3
in: [null,[1]]
expected: [1]
case 4
in: [null,null]
expected: null
case 5
in: [[2],[2]]
expected: [2,[2]]
Starter codePython
def pairing_merge(a, b):
# Your code here
pass5 test cases · run your code against them in the editor