PracticeSearching

Score Found on the Arcade Board

BeginnerSearchingtraversalstate trackingcomparison Time not estimated Not started

Context

An arcade cabinet stores the scores earned during recent runs. The board may be empty, may repeat the same score, and may contain negative or zero scores from special game modes. A player asks whether a particular score appears anywhere on the board.

Problem

Write a function that determines whether the target score occurs in the given score array. Inspect scores from left to right and compare each one with the target. Return true as soon as an equal score is found. If the scan reaches the end without a match, return false. The result is only a membership decision; repeated matches do not change it.

Examples

Example 1
Input: scores = [1200, 850, 975, 1100]target = 975
Output: True
Explanation: The function returns true because 975 occurs in the given scores array. (fact_ids: [""])
Example 2
Input: scores = [250, 400, 525, 600]target = 500
Output: False
Explanation: The function returns false because 500 does not occur in the given scores array. (fact_ids: [""])
Example 3
Input: scores = []target = 0
Output: False
Explanation: The function returns false for the empty array. (fact_ids: [""])

Constraints

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

Function signature

def score_is_recorded(scores: list[int], target: int) -> bool
scores list[int]
The arcade scores currently listed on the board.
target int
The score whose presence should be checked.
returns bool
True if target occurs at least once in scores; otherwise false.

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

Notes

  • The score array may be empty.
  • Duplicate scores do not affect the answer.
Approved · cb026-abs_208_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1