Zero the stock counts of recalled pallet slots

Write codeEasy10 min

Your task

A supplier has recalled some pallets, so the warehouse must stop picking from their slots. The stock system holds one unit count per slot, and the recall arrives as a list of slot positions.

Write zero_recalled(counts, recalled) that returns the counts after the recall.

Input and output:

  • counts: a list of up to 100,000 unit counts, each an integer between 0 and 1,000,000. The slot at position i has count counts[i], with positions counted from 0. It may be empty.
  • recalled: a list of up to 100,000 slot positions. Each one is a position that exists in counts. It may be empty.
  • Returns a list of integers, one per slot, in slot order.

Rules:

  • Every slot whose position appears in recalled has a count of 0 in the result.
  • Every other slot keeps its count.
  • A position can appear in recalled more than once.
  • You may change counts in place and return it, or return a new list.

Examples

zero_recalled(counts: list[int], recalled: list[int]) -> list[int]
Example 1
Inputzero_recalled([5, 3, 8], [0, 2])
Output[0, 3, 0]
Example 2
Inputzero_recalled([4, 4, 4, 4], [1, 1, 3])
Output[4, 0, 4, 0]
Example 3
Inputzero_recalled([2, 7], [])
Output[2, 7]