Apply Bounded Health Deltas
Updated
Problem statement
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[]) → intExamples
Example 1
initialHealth = 12deltas = [-4,-12,6,2]return = 8The health values are 12 -> 8 -> 0 -> 6 -> 8. The second update is clamped at zero.
Example 2
initialHealth = 95deltas = [10,-3]return = 97The first update would reach 105, so it is clamped to 100. The final update reduces it to 97.
Constraints
0 <= initialHealth <= 1001 <= deltas.length <= 100000-100000 <= deltas[i] <= 100000
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Lift Total TravelInfosys · OAInfosys interview questions
- Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
- Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
- Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- First Value Below Both NeighborsCapital One · OACapital One interview questions