O87
Find Median from Data Stream
Problem Statement & Objective
The median is the middle value in an ordered integer list. Design a data structure that supports adding numbers and finding the current median in O(1).
Function Signature (Python)
find_median_from_data_stream(operations: list) -> listInput & Output Contract
Output Rule:İşlem sonuçları listesi (None veya float).
System Constraints
1 <= islemler.length <= 10^4
-10^5 <= val <= 10^5
find_median çağrıldığında en az bir eleman mevcutturExample Execution Walkthrough
islemler = [['add_num', 1], ['add_num', 2], ['find_median'], ['add_num', 3], ['find_median']]
add 1 -> [1]
add 2 -> [1, 2] -> medyan: 1.5
add 3 -> [1, 2, 3] -> medyan: 2.0
Cevap: [None, None, 1.5, None, 2.0]Example Test Scenarios (3)
Example 1: Basic Flow
Input:
[[["add_num",1],["add_num",2],["find_median"],["add_num",3],["find_median"]]]Expected Output:
[null,null,1.5,null,2]Example 2: Negatif Sayılar
Input:
[[["add_num",-1],["find_median"],["add_num",-2],["find_median"]]]Expected Output:
[null,-1,null,-1.5]Example 3: Single Element
Input:
[[["add_num",5],["find_median"]]]Expected Output:
[null,5]