Dashboard
LC #502

IPO

Pattern · ?AmazonGoogleBloomberg

Problem

Maximize capital after completing at most k projects. Each project has a required capital and a profit.

Constraints

  • 1 ≤ k ≤ 10⁵
  • 0 ≤ w ≤ 10⁹
  • n == profits.length == capital.length
  • 1 ≤ n ≤ 10⁵

Example

Input
k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]
Output
4
Why
Start with 0 capital: take project 0 (profit 1) → capital 1. Now take project 2 (profit 3) → capital 4.

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗