Is the Score Run Steady?
Context
In the arcade game Neon Vault, a player’s score is recorded after each level. The game designer wants to detect whether the run progressed steadily: a later score may match an earlier score, but it must never be lower. This helps identify score histories that follow the expected progression.
Problem
Write a function that checks whether the scores in a Neon Vault run are nondecreasing from first to last. A run is valid when no score is greater than any score appearing after it. Equal scores are allowed. Return False as soon as a later score is smaller than the greatest score seen earlier; otherwise return True after the entire list has been checked. An empty or one-score run is valid because it contains no out-of-order pair. Use linear time and constant extra space.
Examples
scores = []Truescores = [12, 12, 15, 15, 21]Truescores = [4, 9, 7, 10]FalseConstraints
0 <= len(scores) <= 100000-1000000 <= scores[i] <= 1000000 for every i- Types:
scoresis int[]; result is bool
Function signature
def is_steady_score_run(scores: list[int]) -> bool
scoreslist[int]- Scores recorded in level order.
- returns bool
- True when the score sequence never decreases relative to its earlier maximum; otherwise False.
Adapted from MBPP problem task_303 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- An empty run is valid.
- Duplicate scores are allowed.
- The scan may stop at the first violation.