PracticeMath

Level-Up Score Streak

EasyMathaccumulationindex arithmeticinvariants Time not estimated Not started

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

Example 1
Input: checkpoint_count = 4initial_score = 10step = 3
Output: 58
Explanation: For initial_score 10, checkpoint_count 4, and step 3, the executed function returns 58.
Example 2
Input: checkpoint_count = 1initial_score = 25step = -7
Output: 25
Explanation: For initial_score 25, checkpoint_count 1, and step -7, the executed function returns 25, which preserves the one-checkpoint requirement.
Example 3
Input: checkpoint_count = 5initial_score = -6step = 2
Output: -10
Explanation: For initial_score -6, checkpoint_count 5, and step 2, the executed function returns -10.

Constraints

  • -1000000 <= initial_score <= 1000000
  • 0 <= checkpoint_count <= 1000000
  • -1000000 <= step <= 1000000
  • Types: initial_score is int, checkpoint_count is int, step is int; result is int

Function signature

def total_level_scores(initial_score: int, checkpoint_count: int, step: int) -> int
initial_score int
The score recorded at the first checkpoint.
checkpoint_count int
The number of checkpoints whose scores are included.
step int
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.

Approved · cb040-abs_789_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1