PracticeArrays

Shift the Score Ladder

EasyArraystraversalaccumulationindex arithmetic Time not estimated Not started

Context

A player’s level scores are recorded in order along a score ladder. After a special move, the ladder advances cyclically: the requested number of leading scores moves to the end, while every score keeps its original cyclic order. Very large move counts may represent repeated full turns.

Problem

Write a function that cyclically shifts a sequence of level scores to the left by the requested number of moves. A left shift moves the first score to the end, repeating this for the displacement amount. A displacement equal to the sequence length changes nothing, and larger displacements wrap around as if complete turns had been removed. If the sequence is empty, return an empty sequence. Preserve every score exactly once, including repeated scores, and keep the relative order within each moved segment.

Examples

Example 1
Input: moves = 2scores = [10, 20, 30, 40, 50]
Output: [30, 40, 50, 10, 20]
Explanation: The split position is 2, so [30, 40, 50] is followed by [10, 20], producing [30, 40, 50, 10, 20].
Example 2
Input: moves = 5scores = [7, 7, 12, 19]
Output: [7, 12, 19, 7]
Explanation: The split position is 1 after normalizing 5 for a sequence of length 4, so the result is [7, 12, 19, 7].
Example 3
Input: moves = 0scores = [3, 8, 15, 21, 34, 55]
Output: [3, 8, 15, 21, 34, 55]
Explanation: The split position is 0, so the output remains [3, 8, 15, 21, 34, 55].

Constraints

  • 0 <= len(scores) <= 100000
  • 0 <= scores[i] <= 1000000 for every i
  • 0 <= moves <= 1000000000
  • Types: scores is int[], moves is int; result is int[]

Function signature

def shift_score_ladder(scores: list[int], moves: int) -> list[int]
scores list[int]
The level scores in their current order.
moves int
The nonnegative number of leftward cyclic moves.
returns list[int]
The scores after the cyclic shift, with the suffix after the effective split placed before the prefix.

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

Notes

  • The input sequence may be empty and may contain repeated values.
  • The result should use proportional extra space and linear time.
Approved · cb031-abs_782_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1