Skip to content

LeetCode 295: Find Median from Data Stream #62

@github-actions

Description

@github-actions

LeetCode 295: Find Median from Data Stream

Category: Heap
Difficulty: See LeetCode
Solution File: src/heap/find_median_from_data_stream.py
Test File: tests/test_find_median_from_data_stream.py

Problem Description

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 values.

Implement the MedianFinder class:

  • MedianFinder() initializes the MedianFinder object.
  • void addNum(int num) adds the integer num from the data stream to the data structure.
  • double findMedian() returns the median of all elements so far.

Example 1:
Input: ["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]
[[], [1], [2], [], [3], []]
Output: [null, null, null, 1.5, null, 2.0]

Constraints:

  • -10^5 <= num <= 10^5
  • There will be at least one element in the data structure before calling findMedian.

Tasks

  • Implement the solution in src/heap/find_median_from_data_stream.py
  • Ensure all test cases pass
  • Analyze time complexity
  • Analyze space complexity

Metadata

Metadata

Assignees

No one assigned

    Labels

    blind-75Blind 75 - Blind-75 problemsheapBlind 75 - Heap problems

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions