Maximize Startup Credits by Funding At Most K Projects

Last updated: November 29, 2026

Quick Overview

A Microsoft for Startups program starts with a credit budget. Each project needs a minimum budget on hand to start and adds a known net gain when done; fund at most k projects one after another and return the largest final budget.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A Microsoft for Startups program starts with a credit budget. Each project needs a minimum budget on hand to start and adds a known net gain when done; fund at most k projects one after another and return the largest final budget.

A two-heap greedy problem in Microsoft onsite style. The interviewer wants the candidate to argue why picking the largest affordable gain each round is optimal and to implement it with a sorted list plus a max-heap.

What the Interviewer Expects
  • Sort projects by required budget
  • Each round, move newly affordable projects into a max-heap of gains
  • Take the largest gain, since gains never reduce the budget
  • Stop early when nothing is affordable
  • Explain the exchange argument for optimality
Key Topics to Cover
heaps
greedy
sorting
two-pointer sweep
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Projects can have negative returns. Does the greedy still work?
  • Several projects can run in parallel if the budget covers all of their requirements.
  • k is huge (up to n) and n is a million. Any concern with this approach?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • budget: starting credits; k: max projects.
  • Project i is available if costs[i] <= budget; finishing it adds returns[i] >= 0.
  • Each project at most once; return the final budget....
High-Level Design

Because gains are non-negative, the budget only grows, so any project affordable now stays affordable. Among those, taking the largest gain is never worse: suppose an optimal plan takes a smaller one ...


Submit Your Answer
Markdown supported