PracticeArrays

Shift the Opening Score

EasyArraystraversalaccumulationstate tracking Time not estimated Not started

Context

In an arcade challenge, a player's score history is recorded in order. The opening score is special: every time that same score appears, it must be moved to the end of the history. All different scores must stay ahead of it and keep their original order.

Problem

Given a list of scores, use its first value as the selected score. Build a new list containing every score different from the selected score, in the order they appeared, followed by every occurrence of the selected score in its original multiplicity. If the list is empty, return an empty list. The input list must not be changed.

Examples

Example 1
Input: scores = [5, 3, 8, 5, 2]
Output: [3, 8, 2, 5, 5]
Explanation: For [5, 3, 8, 5, 2], the executed result is [3, 8, 2, 5, 5].
Example 2
Input: scores = [7, 4, 1, 9]
Output: [4, 1, 9, 7]
Explanation: For [7, 4, 1, 9], the executed result is [4, 1, 9, 7].
Example 3
Input: scores = []
Output: []
Explanation: For an empty input, the executed result is [].

Constraints

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

Function signature

def shift_opening_score(scores: list[int]) -> list[int]
scores list[int]
The scores recorded from first to last.
returns list[int]
A new score list with all occurrences of the original first score moved to the suffix, while all other scores retain their relative order.

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

Notes

  • The source list must remain unmodified.
Approved · c020r1-abs_65_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1