Find the Lightest Shipment
Context
A regional warehouse records the weights of packages loaded onto one delivery route. The dispatch team needs to know the lightest package in the shipment list so it can choose suitable handling equipment. Inspect the recorded weights and report the smallest one.
Problem
Implement a function that receives the package weights for one delivery route and returns the minimum weight. Start with an available package as the current minimum, then scan the remaining weights once. Whenever a smaller weight is found, replace the current minimum. Package weights may be negative, zero, repeated, or all identical. The input always contains at least one weight, so a minimum exists.
Examples
weights = [42]42weights = [7, 7, 7, 7]7weights = [12, 0, -5, 8, -5, 3]-5Constraints
1 <= len(weights) <= 100000-1000000 <= weights[i] <= 1000000 for every iweights: non empty- Types:
weightsis int[]; result is int
Function signature
def find_lightest_shipment(weights: list[int]) -> int
weightslist[int]- The recorded integer weights of packages on one delivery route.
- returns int
- The smallest package weight in weights.
Adapted from MBPP problem task_62 (CC BY 4.0). Rewritten, extended and verified by Iksha.