Two-heaps

6 articles

dsa2 min read

Find Median from Data Stream

Maintain a dynamic median using two heaps: a max-heap for the lower half and a min-heap for the upper half.

Read →
dsa3 min read

Sliding Window Median

Compute medians of all sliding windows using two heaps with lazy deletion for element removal.

Read →
dsa2 min read

IPO

Maximize capital after k IPO investments by greedily picking the highest profit project among affordable ones.

Read →
dsa3 min read

Process Tasks Using Servers

Assign tasks to available servers using two heaps: one for free servers and one for busy servers sorted by free time.

Read →
dsa2 min read

Total Cost to Hire K Workers

Minimize total hiring cost by always choosing the cheapest candidate from the first or last p candidates using two min-heaps.

Read →