A small design studio starts with capital dollars and can take on at most k projects. Project i needs at least minCapital[i] dollars in the bank to start and adds profit[i] dollars when finished (the starting money isn't spent). Projects are done one at a time, and each can be done once.
Write bestFinalCapital(k, capital, profit, minCapital) that returns the most money the studio can have after finishing at most k projects.
Input: k = 2, capital = 0, profit = [1,2,3], minCapital = [0,1,1] Output: 4
Only project 0 is affordable at first (+1). Then project 2 is affordable (+3), for 4.
Input: k = 3, capital = 0, profit = [1,2,3], minCapital = [0,1,2] Output: 6
Do all three projects in order: 0, then 1, then 2.
1 <= k <= 1000000 <= capital <= 10^90 <= profit.length === minCapital.length <= 1000000 <= profit[i] <= 10^4, 0 <= minCapital[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #576 Fund Projects to Grow Capital. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.