Interview Questions/Coding/Launch Projects for Maximum Capital

Launch Projects for Maximum Capital

Preview mode. Log in to edit, run, submit, and save progress.

Hard

Launch Projects for Maximum Capital

A launch fund starts with some initial capital and has a list of candidate projects. Each project has a required starting capital and a profit that is added immediately after completing the project. You may launch at most picks projects. At any moment, only projects whose required capital is less than or equal to your current capital are available. Once a project is chosen, it cannot be chosen again, and its profit becomes part of your capital before the next selection. Determine the highest possible final capital after making up to picks project selections. Input Format: You are given picks, initialCapital, profits, and requiredCapital. For project i, profits[i] is its gain and requiredCapital[i] is the capital needed before starting it. Output Format: Return the maximum capital reachable after completing at most picks projects.

Examples

Example 1
Input:
picks = 2
initialCapital = 0
profits = [1, 2, 3]
requiredCapital = [0, 1, 1]
Output:
4

Explanation: capital 0, launch profit 1; capital 1, launch profit 3. Final capital is 4, matching the output 4.

Approach hint

Separate projects you cannot afford yet from projects you can afford now.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp