PracticeArrays
Total the Warehouse Registry Values
Context
A logistics company keeps a shipment registry mapping internal shipment codes to package weights. The registry system supplies its stored numeric values as an array, while the codes are omitted because they do not affect the calculation. Find the combined weight of all registered shipments.
Problem
Implement a function that returns the total of every value in the given shipment registry. Start with the additive identity, inspect each value exactly once, and add it to a running total. The registry may contain no shipments, zero weights, negative adjustments, or large values within the stated limits. Return the final total after all values have been processed.
Examples
Example 1
Input:
values = []Output:
0Explanation: The empty registry returns 0. (fact_ids:, )
Example 2
Input:
values = [12, 0, 7, 0]Output:
19Explanation: The values 12, 0, 7, and 0 produce a returned total of 19. (fact_ids:, )
Example 3
Input:
values = [25, -8, 13, -5]Output:
25Explanation: The values 25, -8, 13, and -5 produce a returned total of 25 after signed contributions are accumulated. (fact_ids:, )
Constraints
0 <= len(values) <= 100-1000000 <= values[i] <= 1000000 for every i- Types:
valuesis int[]; result is int
Function signature
def sum_registry_values(values: list[int]) -> int
valueslist[int]- Numeric values stored in the shipment registry, in any order.
- returns int
- The sum of every value in values, or 0 when the registry is empty.
Adapted from MBPP problem task_796 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Code
Saved