Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
Suppose LeetCode will start its IPO soon. In order to sell a good price, the company would like to work on at most `k` distinct projects before the IPO. Help the company maximize total capital after finishing at most `k` distinct projects. You are given `n` projects with `profits[i]` and `capital[i]`. Initially, you have `w` capital. When you finish a project, you gain its profit (added to your total capital). Pick a list of at most `k` distinct projects to maximize your final capital, and return the final maximized capital. You can only start a project if your current capital is `≥ capital[i]`.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.