PracticeArrays

Total the Audit Token Scores

BeginnerArraystraversalaccumulationstate tracking Time not estimated Not started

Context

An archive system assigns an integer score to each token found in a document audit log. The scores may be positive, negative, or zero, and repeated scores remain separate entries. Return the combined score for the complete log, including the neutral result when no tokens were recorded.

Problem

Write a function that receives the integer scores from one document audit log and returns their total. Process the sequence from beginning to end, adding each score exactly once to a running total that starts at zero. Do not discard repeated values or treat zero as a special stopping signal. An empty log has total zero.

Examples

Example 1
Input: scores = []
Output: 0
Explanation: The empty log returns 0, matching the required empty-sequence result.
Example 2
Input: scores = [5, 0, -2, 5, 3]
Output: 11
Explanation: The log [5, 0, -2, 5, 3] returns 11 after including both 5 values and the zero.
Example 3
Input: scores = [12, -7, 0, -7, 4, 12]
Output: 14
Explanation: The log [12, -7, 0, -7, 4, 12] returns 14 after including both 12 values and both -7 values.

Constraints

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

Function signature

def sum_audit_scores(scores: list[int]) -> int
scores list[int]
The integer score attached to each token in the audit log, in log order.
returns int
The sum of all values in scores; returns 0 when the log contains no scores.

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

Notes

  • The result must preserve the exact integer total.
Approved · c009r1-abs_198_v414 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1