Pick Up to K Projects to Maximize the Team's Engineering Budget

Last updated: November 29, 2026

Quick Overview

Each project needs a minimum budget to start and returns a net gain when done. Starting from budget w and finishing at most k projects in sequence, return the largest budget you can reach.

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

0

0

0 solved


Each project needs a minimum budget to start and returns a net gain when done. Starting from budget w and finishing at most k projects in sequence, return the largest budget you can reach.

Asked in Meta onsites as a two-structure greedy: one ordering by cost to unlock projects, one heap by gain to choose among them. Interviewers check the exchange argument for why picking the largest affordable gain is optimal.

What the Interviewer Expects
  • Sort projects by required budget
  • Push newly affordable projects into a max-heap by gain
  • Pick the best affordable project k times
  • Stop early when nothing is affordable
  • Justify the greedy with an exchange argument
Key Topics to Cover
greedy
max-heap
sorting
exchange argument
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
  • What if gains can be negative?
  • What if projects can run in parallel up to some limit?
  • Return the chosen projects, not just the final budget.
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
  • Inputs: k, starting budget w, arrays costs and gains.
  • A project can start only if current budget >= cost; the cost is not spent (it is a threshold), and finishing adds gain (non-negati...
High-Level Design

Since gains are non-negative, the budget only grows, so the set of affordable projects only grows. That suggests a sweep:

  1. Sort projects by cost.
  2. Before each pick, move every newly affordable pr...

Submit Your Answer
Markdown supported