PracticeArrays

Is the Score Run Steady?

EasyArraystraversalaccumulationstate tracking Time not estimated Not started

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

Example 1
Input: scores = []
Output: True
Explanation: The empty list returns True because an empty run is valid; the final values include is_valid=true and scan_index=0. (fact_ids:,, )
Example 2
Input: scores = [12, 12, 15, 15, 21]
Output: True
Explanation: The list [12, 12, 15, 15, 21] returns True, and the trace ends with is_valid=true, prefix_peak=21, and scan_index=5. (fact_ids:, )
Example 3
Input: scores = [4, 9, 7, 10]
Output: False
Explanation: The list [4, 9, 7, 10] returns False because its trace ends with is_valid=false after scan_index=2 and prefix_peak=9. (fact_ids:, )

Constraints

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

Function signature

def is_steady_score_run(scores: list[int]) -> bool
scores list[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.
Approved · cd001-abs_757_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1