Max-heap

7 articles

dsa2 min read

Last Stone Weight

Simulate stone smashing by repeatedly extracting the two heaviest stones using a max-heap.

Read →
dsa2 min read

Task Scheduler

Find minimum CPU intervals to schedule tasks with cooldown using a greedy max-heap simulation.

Read →
dsa3 min read

Reorganize String

Rearrange a string so no two adjacent characters are the same using a greedy max-heap approach.

Read →
dsa2 min read

Course Schedule III

Maximize courses taken within deadlines by greedily scheduling and swapping out the longest past course.

Read →
dsa2 min read

Minimum Number of Refueling Stops

Find minimum fuel stops to reach the target by greedily selecting the largest available fuel stations when running low.

Read →
dsa2 min read

Longest Happy String

Build the longest string with at most 2 consecutive identical characters by always using the most frequent available character.

Read →
dsa2 min read

Minimize Deviation in Array

Minimize max-min of an array by doubling odd numbers and repeatedly halving the max using a max-heap.

Read →