Razorpay Settlement Heap Two-Phase
Razorpay Settlement Heap Two-Phase
HardHeaps100% accepted
Razorpay has a dual settlement queue: incoming payment requests sorted by urgency, and outgoing settlements sorted by value. Design a system using two heaps to efficiently find the median settlement amount at any time (similar to Find Median from Data Stream).
Approach
Design a data structure that finds median from a stream in O(log n) insert, O(1) find median.
Input
addNum(1)
findMedian()
addNum(2)
findMedian()
addNum(3)
findMedian()
Output
1 1.5 2
More Heaps problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards