Keep Eligible Shipment IDs
Context
A regional warehouse prepares a dispatch list of shipment IDs. Some IDs belong to deliveries temporarily held at another facility and must be excluded. Create the final dispatch list by removing every source ID that appears in the hold list, while keeping all remaining IDs in their original order.
Problem
Given a list of shipment IDs scheduled for dispatch and a list of shipment IDs currently on hold, return a new list containing exactly the scheduled IDs that do not occur in the hold list. Examine each scheduled occurrence independently: if its value appears anywhere in the hold list, omit it; otherwise, retain it. Preserve the relative order of all retained IDs. Repeated scheduled IDs must be treated consistently, and neither input list should be modified.
Examples
held_ids = [2087]scheduled_ids = [1042, 2087, 1042, 3150][1042, 1042, 3150]held_ids = []scheduled_ids = [501, 502, 503, 504][501, 502, 503, 504]held_ids = [7001, 7002]scheduled_ids = [7001, 7002, 7001][]Constraints
0 <= len(scheduled_ids) <= 1000 <= scheduled_ids[i] <= 1000000 for every i0 <= len(held_ids) <= 1000 <= held_ids[i] <= 1000000 for every i- Types:
scheduled_idsis int[],held_idsis int[]; result is int[]
Function signature
def filter_eligible_shipments(scheduled_ids: list[int], held_ids: list[int]) -> list[int]
scheduled_idslist[int]- Shipment IDs in the warehouse's planned dispatch order.
held_idslist[int]- Shipment IDs that must not be dispatched.
- returns list[int]
- A new integer list containing scheduled IDs absent from held_ids, in their original order and with every qualifying occurrence retained.
Adapted from MBPP problem task_484 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- An empty input list is valid.
- Input lists must remain unchanged.