Plan load probes for a new agent version
Your task
Before a new version of your agent takes full traffic, you want to know how much it can carry. There are levels load levels, numbered from 1. The version holds at every level up to some highest safe level, which may be 0 or levels, and it breaks at every level above that. One probe runs the version at one level for an hour. A probe that breaks pages the on-call team and forces a rollback, and they have agreed to at most rollbacks of those this week.
Write probe_plan(levels, rollbacks) that returns how many probes the best plan needs and where it can start.
Input and output:
levels: a whole number from 1 to 1,000,000,000.rollbacks: a whole number from 1 to 100.- Return
[probes, first], two whole numbers.
Rules:
- A plan picks each probe's level after seeing every earlier result. It must always end knowing the highest safe level. It must never risk more than
rollbacksbroken probes, whatever the results are. - A plan's worst case is the most probes it can use over every possible highest safe level.
probesis the smallest worst case of any plan. firstis the lowest level that can be the first probe of a plan whose worst case isprobes.
Examples
probe_plan(levels: int, rollbacks: int) -> list[int]Example 1
Input
probe_plan(100, 2)Output
[14, 9]Example 2
Input
probe_plan(8, 1)Output
[8, 1]Example 3
Input
probe_plan(7, 3)Output
[3, 4]