Weather Sleeve Decision Budget

Minimum worst-case testing time and earliest optimal first test

Hard2-D Dynamic ProgrammingMonotone OptimizationDecision Trees

A weather station is certifying protective sleeves for a cold chamber. The chamber has integer intensity settings from 1 through levels.

There is an unknown integer threshold t between 0 and levels, inclusive. Every sleeve behaves identically:

  • A test at intensity x <= t leaves the sleeve intact and takes safe_time units of time.
  • A test at intensity x > t breaks the sleeve and takes break_time units of time.

The station starts with sleeves sleeves. An intact sleeve may be tested again, but a broken sleeve cannot be reused. Tests happen one at a time, and the next intensity may depend on all previous outcomes. There are no other time costs.

A testing strategy must determine t exactly for every possible threshold, without using more sleeves than are available. Its worst-case time is the largest total testing time over all possible thresholds.

Return [minimum_time, first_intensity], where:

  • minimum_time is the smallest achievable worst-case time.
  • first_intensity is the smallest first test intensity among all strategies achieving minimum_time.

If levels is 0, the threshold is already known; return [0, 0].

Examples

Example 1

Input: levels = 3, sleeves = 1, safe_time = 1, break_time = 2
Output: [4,1]

With one sleeve, the station must test intensities in increasing order: breaking the only sleeve while multiple lower thresholds remain would make exact identification impossible. Testing intensity 1 first gives a worst-case time of 4.

Example 2

Input: levels = 3, sleeves = 2, safe_time = 1, break_time = 1
Output: [2,2]

Testing intensity 2 first separates the four possible thresholds into two pairs. Each outcome needs just one more test, so every threshold can be identified within 2 time units. Starting at intensity 1 cannot achieve that guarantee.

Example 3

Input: levels = 0, sleeves = 5, safe_time = 7, break_time = 3
Output: [0,0]

There is only one possible threshold when there are no positive intensity settings, so no sleeve or testing time is needed.

Constraints

  • 0 <= levels <= 100000
  • 1 <= sleeves <= 30
  • 1 <= safe_time <= 1000000
  • 1 <= break_time <= 1000000
  • All inputs are integers.

The intended solution takes O(sleeves * levels) time and O(levels) auxiliary space. A direct implementation that tries every first intensity for every state takes O(sleeves * levels^2) time and is too slow. The unknown threshold is fixed throughout testing, and all sleeves share that threshold.

Hints

Show hint 1

Let D[e][n] be the minimum worst-case time for an uncertain range containing n testable boundaries and e available sleeves. What two smaller ranges result from choosing the x-th boundary?

Show hint 2

For a fixed state, the broken-outcome cost is nondecreasing in x, while the intact-outcome cost is nonincreasing. As n grows, the first crossing of these costs never moves left.

Follow-up questions

What an interviewer might ask once you have a working solution.

  • How would you reconstruct an entire optimal adaptive strategy while choosing the smallest optimal intensity at every decision?
  • If both outcome durations were equal, could you instead track how many thresholds can be distinguished within a fixed number of tests?

Practice this with an AI interviewer

Explain your approach out loud, write Python or JavaScript, run it against hidden tests (including large inputs), and get a scored debrief.

Start this problem