PracticeHashing

Keep Eligible Shipment IDs

EasyHashingtraversalfilteringset membership Time not estimated Not started

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

Example 1
Input: held_ids = [2087]scheduled_ids = [1042, 2087, 1042, 3150]
Output: [1042, 1042, 3150]
Explanation: In the first example, both occurrences of 1042 and the occurrence of 3150 are retained, while 2087 is excluded because it appears in held_ids; the executed result is [1042, 1042, 3150].
Example 2
Input: held_ids = []scheduled_ids = [501, 502, 503, 504]
Output: [501, 502, 503, 504]
Explanation: In the second example, held_ids is empty, so all four scheduled occurrences are retained in their original order; the executed result is [501, 502, 503, 504].
Example 3
Input: held_ids = [7001, 7002]scheduled_ids = [7001, 7002, 7001]
Output: []
Explanation: In the third example, every scheduled occurrence has a value present in held_ids, so the executed result is an empty list.

Constraints

  • 0 <= len(scheduled_ids) <= 100
  • 0 <= scheduled_ids[i] <= 1000000 for every i
  • 0 <= len(held_ids) <= 100
  • 0 <= held_ids[i] <= 1000000 for every i
  • Types: scheduled_ids is int[], held_ids is int[]; result is int[]

Function signature

def filter_eligible_shipments(scheduled_ids: list[int], held_ids: list[int]) -> list[int]
scheduled_ids list[int]
Shipment IDs in the warehouse's planned dispatch order.
held_ids list[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.
Approved · c015-abs_938_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1