Step 1: Add 5 to max heap (smaller half)
MaxHeap: 5 -> null
MinHeap: null
Why: Start by adding first number to max heap to hold smaller half
Step 2: Add 15 to min heap (larger half)
MaxHeap: 5 -> null
MinHeap: 15 -> null
Why: Add next number to min heap to hold larger half
Step 3: Add 1 to max heap (smaller half)
MaxHeap: 5 -> 1 -> null
MinHeap: 15 -> null
Why: Add smaller number to max heap to keep smaller half
Step 4: No balancing needed
MaxHeap: 5 -> 1 -> null
MinHeap: 15 -> null
Why: maxHeap.size() = 2 == minHeap.size() + 1, which is allowed; median = maxHeap.top() = 5
Step 5: Add 3 to max heap (smaller half)
MaxHeap: 5 -> 1 -> 3 -> null
MinHeap: 15 -> null
Why: 3 <= maxHeap.top() = 5, so add to smaller half
Step 6: Balance heaps to keep size difference ≤ 1
MaxHeap: 3 -> 1 -> null
MinHeap: 5 -> 15 -> null
Why: maxHeap.size() = 3 > minHeap.size() + 1 = 2, so move maxHeap.top() = 5 to minHeap and pop it from maxHeap
Result: After each insertion, medians are: 5, 10, 5, 4
Final heaps:
MaxHeap: 3 -> 1 -> null
MinHeap: 5 -> 15 -> null