HeapEvidence Contributing

Two Heaps (Median Maintenance)

Balance a max-heap of the lower half against a min-heap of the upper half to maintain a running median.

Practice Problems: 1
Difficulty: 0 Easy·0 Medium·1 Hard

Algorithmic Intuition & Recognition

The Two Heaps (Median Maintenance) technique is applied when tackling problems characterized by specific invariants in the problem state or constraints:

  • Core Strategy: Balance a max-heap of the lower half against a min-heap of the upper half to maintain a running median.
  • When to use: Look for opportunities where repeated re-computation can be replaced by maintaining monotonic properties, state windows, or relational pointers.
  • Interview Signal: Demonstrating this pattern shows mastery of Heap foundations, reducing worst-case algorithmic complexity.

Canonical Practice Problems

1 problem

Curated Sheets Containing This Pattern

Related Algorithmic Patterns