15% off all plans & roadmaps Use code
See plansProblem editorial
You are given a collection of projects. Project i requires capital[i] units of capital to begin and produces profits[i] units of profit when completed. The two arrays describe matching projects, so project i uses the values at index i in both arrays; each project may be completed at most once.
IPO is a Heap (Priority Queue) Patterns problem, in the Scheduling / Minimum Cost (Greedy with Priority Queue) subpattern. The pattern covers top K elements, K-way merge, two heaps for median, and scheduling
The reference solution runs in O(n log n + k log n), where n is the number of projects. time and O(n) space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
IPO is a Heap (Priority Queue) Patterns problem, in the Scheduling / Minimum Cost (Greedy with Priority Queue) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.