bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 480. Sliding Window Median

480. Sliding Window Median

Leetcode Solutions

Approach: Two Heaps (Lazy Removal)

  1. Initialize two heaps: a max-heap lo and a min-heap hi.
  2. Initialize a hash table to keep track of invalid elements.
  3. For each window: a. Insert the incoming element into the appropriate heap. b. Remove the outgoing element from the heap by marking it in the hash table. c. Balance the heaps by moving elements between them if necessary. d. Remove the top elements of the heaps if they are marked as invalid in the hash table. e. Calculate the median based on the tops of the heaps.
UML Thumbnail

Approach: Simple Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR