PracticeArrays

Jumping Score Streak

BeginnerArraystraversalaccumulationindex arithmetic Time not estimated Not started

Context

During a game run, a tracker records the score earned after each move. A special review mode checks the first recorded score, then skips a fixed number of positions before checking the next one. Build the score streak that this review mode sees.

Problem

Implement a function that receives a list of move scores and a positive stride. Select the score at position 0, then continue at positions obtained by repeatedly adding the stride. Keep only positions inside the list and preserve their original order. If the list is empty, return an empty list. A stride larger than the list can still select the first score when one exists. The input list must not be changed.

Examples

Example 1
Input: scores = [12, 7, 19, 4, 15, 22]stride = 2
Output: [12, 19, 15]
Explanation: With scores [12, 7, 19, 4, 15, 22] and stride 2, the executed result is [12, 19, 15].
Example 2
Input: scores = [5, 11, 18, 24, 31]stride = 3
Output: [5, 24]
Explanation: With scores [5, 11, 18, 24, 31] and stride 3, the executed result is [5, 24].
Example 3
Input: scores = [9, 14]stride = 5
Output: [9]
Explanation: With scores [9, 14] and stride 5, the executed result is [9], so a stride larger than the list still selects the first score.

Constraints

  • 0 <= len(scores) <= 100
  • -100000 <= scores[i] <= 100000 for every i
  • 1 <= stride <= 100
  • Types: scores is int[], stride is int; result is int[]

Function signature

def extract_score_streak(scores: list[int], stride: int) -> list[int]
scores list[int]
Scores recorded after consecutive moves.
stride int
Positive distance between selected score positions.
returns list[int]
The scores at positions 0, stride, 2 times stride, and so on while those positions remain valid, in source order.

Adapted from MBPP problem task_536 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Notes

  • Positions are zero-based.
  • Only positive strides are allowed by the input constraints.
Approved · c045-abs_400_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1