#3679

Minimum Discards to Balance Inventory

expert · 1085 · lc medium +32 · 34.8% accepted · 78 likes · top 12%

Description

Integers w, m, and an array arrivals are given where arrivals[i] is the item type arriving on day i. Each arrival can be kept or discarded (only on its arrival day). Within every sliding window of w consecutive days, each type may appear at most m times among kept items; if keeping an item would violate this, it must be discarded. Return the minimum total discards required.

Code

1
2
3