Reported September 2024
ZipRecruitersimulation

Apply Bounded Health Deltas

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

ZipRecruiter reported this one in September 2024, and the first thing to know is that the data structure is just an array you walk once. There's no hash map, no heap, no trick container. You hold one integer, health, and feed each delta through it. Apply the change, clamp to 0 through 100, move on. If you're taking this OA in the next couple of days, it's a warm-up simulation, and the only way to lose it is overthinking. StealthCoder sits invisibly on your screen as a safety net if you blank on a basic loop, but you probably won't need it here.

The problem

Start with initialHealth. Apply each integer in deltas from left to right.
After every delta, clamp health to the inclusive range from 0 through 100: values below zero become zero, and values above one hundred become one hundred.
Return the final health after every delta has been processed.

Function
applyBoundedHealthDeltas(initialHealth: int, deltas: int[]) → int

Examples
Example 1
initialHealth = 12
deltas = [-4,-12,6,2]
return = 8
The health values are 12 -> 8 -> 0 -> 6 -> 8. The second update is clamped at zero.
Example 2
initialHealth = 95
deltas = [10,-3]
return = 97
The first update would reach 105, so it is clamped to 100. The final update reduces it to 97.

Constraints
0 <= initialHealth <= 100
1 <= deltas.length <= 100000
-100000 <= deltas[i] <= 100000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that clamping happens after every delta, not once at the end. That's the whole problem. Summing all deltas and clamping the total gives the wrong answer. Example 1 shows it: 12, then -4 gives 8, then -12 would hit -4 but clamps to 0, then +6 and +2 give 8. A running total would say 4. So keep a single variable and write health = min(100, max(0, health + d)) inside the loop. That's O(n) time and O(1) space, and n up to 100000 is trivial. Pitfalls are small. Don't clamp only on one side. Don't early-return when health hits 0, because later positive deltas can bring it back up. Don't sort or reorder the deltas. If you blank on the clamp syntax during the live OA, StealthCoder is the hedge, but this is a two-minute problem.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Apply Bounded Health Deltas cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Apply Bounded Health Deltas FAQ

How hard is the Apply Bounded Health Deltas problem really?+

Easy. It's a single-pass simulation with one running integer. The ZipRecruiter version reported in September 2024 has no hidden edge cases beyond clamping after every step. If you can write a for loop with min and max, you can solve it.

What's the trick to this problem?+

Clamp after every delta, not at the end. Order matters because hitting 0 or 100 discards the overflow. Summing everything and clamping once gives wrong answers, as Example 1 shows with 12 ending at 8, not 4.

Do I need a special data structure?+

No. One integer variable and the input array are enough. No stack, heap, or map. Iterate left to right, update health, clamp, and return it after the loop finishes. Space is O(1).

Will 100000 deltas cause a performance problem?+

No. A single linear pass is O(n), so 100000 elements is nothing. Deltas up to 100000 in magnitude fit easily in a normal 32-bit integer since health is clamped to 0 through 100 each step.

How do I prepare for this in 48 hours?+

Don't study this one specifically. Just be comfortable with loops, min/max, and reading examples carefully. Trace Example 1 by hand to confirm the clamp-each-step logic, then spend remaining time on harder pattern problems that might show up alongside it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it