Character Health in a Video Game
Learn this problemProblem statement
Note - Feel free to checkout the srce image below for the original statement :)
Imagine a magical adventure where you guide a brave character through a series of enchanting levels. The character begins this journey with an initial health value, a precious resource that fluctuates as they encounter various challenges in each level.
As you progress through these levels, each experience, whether it's a thrilling battle or a rewarding discovery, influences the character’s health. These changes are captured in an array of integers, deltas, where the value at each level determines how much the character's health increases or decreases.
However, there's a twist! If the character's health ever falls below 0, it's lovingly set to 0, ensuring they never completely lose hope. On the other hand, if their health exceeds 100, it gently settles back down to 100, keeping them from becoming too invincible.
Your quest is to guide this character through all the levels, and at the end, discover their final health value after all these adventures. The goal isn’t necessarily to find the most cunning solution, but rather one that reliably determines the character's final health without taking too long.
So, with that in mind, how will your character's health fare by the end of their journey? Let's find out!
Function
characterHealthInVideoGame(initialHealth: int, deltas: int[]) → intExamples
Example 1
initialHealth = 12deltas = [-4, -12, 6, 2]return = 8Constraints
🍉🍉More Uber problems
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026