PracticeHashing

Unique Scores in the Arena

Easy/MediumHashingtraversalstate trackinginvariants Time not estimated Not started

Context

In a gaming arena, a match records the score earned after each move. The referee needs to know whether every recorded score is different. Decide whether the score sequence contains no repeated value, including when the sequence is empty or has only one score.

Problem

Write a function that checks whether all scores in the supplied sequence are distinct. Inspect the scores from left to right. A score that has already appeared means the sequence is not unique, so the function should report failure immediately. If the entire sequence is inspected without finding a repeated score, report success. An empty sequence is considered unique.

Examples

Example 1
Input: scores = []
Output: True
Explanation: The empty sequence returns true, so the empty sequence is considered unique.
Example 2
Input: scores = [10, 25, 7, 42]
Output: True
Explanation: The sequence [10, 25, 7, 42] returns true after position reaches 4, with no repeated score reported.
Example 3
Input: scores = [3, 8, 3, 12]
Output: False
Explanation: The sequence [3, 8, 3, 12] returns false when the previously seen score is encountered at position 2.

Constraints

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

Function signature

def has_unique_scores(scores: list[int]) -> bool
scores list[int]
The scores recorded during the match, in move order.
returns bool
Return true when no score appears more than once; otherwise return false.

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

Notes

  • The input sequence must not be reordered or changed.
  • Use a membership structure so repeated scores can be detected during one left-to-right scan.
Approved · cc003-abs_735_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1