Keep Even Shipment Values
Context
A warehouse records one integer handling value for each shipment on a dispatch manifest. The operations team wants a new manifest containing only values divisible by two. The retained values must stay in their original order, and repeated values must remain repeated.
Problem
Write a function that receives the shipment handling values from a warehouse manifest and returns a new array containing exactly the values divisible by two. Inspect the input from left to right. Keep zero and negative values when they are divisible by two, preserve the order of all retained values, and preserve their multiplicity. If no value qualifies, return an empty array. Do not modify the input array.
Examples
shipment_values = [7, 12, 3, 8, 5][12, 8]shipment_values = [0, -6, 4, -6, 9][0, -6, 4, -6]shipment_values = [1, -3, 5, 7][]Constraints
0 <= len(shipment_values) <= 100000-1000000000 <= shipment_values[i] <= 1000000000 for every i- Types:
shipment_valuesis int[]; result is int[]
Function signature
def filter_even_shipments(shipment_values: list[int]) -> list[int]
shipment_valueslist[int]- Integer handling values listed in manifest order.
- returns list[int]
- A new array containing the divisible-by-two shipment values in their original order, including duplicates.
Adapted from MBPP problem task_629 (CC BY 4.0). Rewritten, extended and verified by Iksha.