loading

IPO — Step-by-Step Visualization

hardLeetCode #502ArrayGreedySortingHeap (Priority Queue)

You have k projects available. Each project has profit[i] and capital[i] requirement. Starting with capital w, select at most k projects (sequentially) to maximize final capital.

Algorithm Pattern

Greedy Two-Phase

Key Idea

Sort projects by capital; at each round, pick the highest-profit affordable project.

Step-by-Step Approach

  1. Sort by capital requirement
  2. For k rounds:
  3. Push all projects with capital <= w to max-heap
  4. Pop max profit, add to w

Related Problems