3679. Minimum Discards to Balance Inventory
You are given two integers
wandm, and an integer arrayarrivals, wherearrivals[i]is the type of item arriving on dayi(days are 1-indexed).Items are managed according to the following rules:
Each arrival may be kept or discarded; an item may only be discarded on its arrival day.
For each day
i, consider the window of days[max(1, i - w + 1), i](thewmost recent days up to dayi):
- For any such window, each item type may appear at most
mtimes among kept arrivals whose arrival day lies in that window.- If keeping the arrival on day
iwould cause its type to appear more thanmtimes in the window, that arrival must be discarded.Return the minimum number of arrivals to be discarded so that every
w-day window contains at mostmoccurrences of each type.
1 | class Solution { |