A product team wants to run as many A/B experiments as possible this month. Experiment i is given as experiments[i] = [cpu, memory], the server CPU units and memory units it needs. The month's budgets are cpuBudget and memoryBudget, and each experiment is run at most once.
Write mostExperiments(experiments, cpuBudget, memoryBudget) that returns the largest number of experiments whose total CPU stays within cpuBudget and whose total memory stays within memoryBudget.
Input: experiments = [[1,2],[1,1],[2,1]], cpuBudget = 3, memoryBudget = 3 Output: 2
Any two fit (for example the first two use 2 CPU and 3 memory), but all three need 4 and 4.
Input: experiments = [[2,2],[2,2]], cpuBudget = 1, memoryBudget = 5 Output: 0
Each experiment needs 2 CPU, but the budget is 1.
1 <= experiments.length <= 1000 <= cpu, memory <= 1000 <= cpuBudget, memoryBudget <= 100Run 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 #515 Most Experiments Within Two Budgets. 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.