FastPrepRating Level After Changes

Rating Level After Changes

TikTok logoTikTok● EasyINTERNOA
Learn

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[]) → String

Examples

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 changes never makes the rating less than 1 or greater than 2500.
  • The visible source states that O(changes.length^2) time fits within the execution limit.

More TikTok problems

See TikTok hiring insights
public String ratingLevelAfterChanges(int initial, int[] changes) {
    // Write your code here.
}
initial1500
changes[-100,-300,450,500,-500,-600]
expected"beginner"
Checking account…