← Questions
Maximize capital with K projects (IPO)
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Apple's technical phone screen, last asked Jul 2025. It tests greedy and heaps.
You start with capital w and may complete at most k projects, each at most once. Project i needs at least capital[i] to start (the capital is not spent) and adds profits[i] to your capital when done. Choose projects to end with the most capital.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
max_capital(k: int, w: int, profits: list[int], capital: list[int]) -> int: the final capital.
Example
max_capital(2, 1, [2, 5, 3, 4], [0, 3, 1, 6]) -> 9 # take profit 3 (needs 1), then profit 5 (needs 3)
max_capital(3, 1, [2, 5, 3, 4], [0, 3, 1, 6]) -> 13 # then profit 4 (needs 6)
max_capital(3, 0, [5], [1]) -> 0 # nothing affordable
Constraints
-
1 <= n <= 2 * 10^5,0 <= k <= n -
0 <= profits[i], capital[i]; capital fits in a 64-bit integer.
Clarifying questions
- Is capital consumed when a project starts, or only a threshold?
- Can profits be negative?
- Must I use exactly
kprojects, or at mostk?
What a strong answer covers
- The greedy rule: at each step take the affordable project with the highest profit, and why it is safe (more capital never makes fewer projects affordable).
- Projects sorted by required capital and a pointer that moves into a max-heap of profits as capital grows. O(n log n + k log n).
- Stopping early when nothing is affordable.
- Tests: nothing affordable,
klarger than useful, ties in capital, zero profits.
Follow-ups
- Projects take time and you have a deadline.
- Capital is consumed when a project starts.
- Return which projects you chose.
Where it's asked
- Apple · Technical phone screen · Last asked Jul 2025
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
