Rating Level After Changes
Problem statement
You are given an integer initial, representing a user's initial rating, and an integer array changes. Apply every value in changes to the rating in order.
After all changes have been applied, return the level corresponding to the final rating:
rating < 1000:"beginner"1000 ≤ rating < 1500:"intermediate"1500 ≤ rating < 2000:"advanced"2000 ≤ rating:"pro"
Function
ratingLevelAfterChanges(initial: int, changes: int[]) → StringExamples
Example 1
initial = 1500changes = [-100,-300,450,500,-500,-600]return = "beginner"The rating changes as follows: 1500 → 1400 → 1100 → 1550 → 2050 → 1550 → 950. Since 950 < 1000, the final level is "beginner".
Constraints
1 ≤ initial ≤ 2500- Applying the values in
changesnever makes the rating less than1or greater than2500. - The visible source states that
O(changes.length^2)time fits within the execution limit.