Level-Up Score Streak
Context
In the game Skyforge Sprint, a player records a score at each checkpoint of a special challenge. The first checkpoint has a known score, and every later checkpoint changes the score by the same fixed amount. The challenge may contain no checkpoints. Calculate the combined score across all checkpoints.
Problem
Implement a function that calculates the total score recorded across a challenge's checkpoints. The first checkpoint score is given by initial_score, the number of checkpoints is checkpoint_count, and each successive checkpoint changes by step. The checkpoint scores form an arithmetic sequence: the first score is initial_score, and each next score is step more than the previous one. If checkpoint_count is zero, no score contributes and the total is zero. Return the exact total without simulating individual checkpoints. Negative scores and negative steps are valid.
Examples
checkpoint_count = 4initial_score = 10step = 358checkpoint_count = 1initial_score = 25step = -725checkpoint_count = 5initial_score = -6step = 2-10Constraints
-1000000 <= initial_score <= 10000000 <= checkpoint_count <= 1000000-1000000 <= step <= 1000000- Types:
initial_scoreis int,checkpoint_countis int,stepis int; result is int
Function signature
def total_level_scores(initial_score: int, checkpoint_count: int, step: int) -> int
initial_scoreint- The score recorded at the first checkpoint.
checkpoint_countint- The number of checkpoints whose scores are included.
stepint- The constant score change from one checkpoint to the next.
- returns int
- The exact sum of the scores at all checkpoints, or zero when there are no checkpoints.
Adapted from MBPP problem task_335 (CC BY 4.0). Rewritten, extended and verified by Iksha.