Tap here to switch tabs
Problem
Submissions

Problem: Minimum Discards to Balance Inventory

med
30 min
Try to solve the Minimum Discards to Balance Inventory problem.

Statement

You are given an integer array arrivals, where arrivals[i] represents the type of item that arrives on day i, and two integers w and m.

Items arrive sequentially from day 00 to day arrivals.length −1- 1. For each day i, an arriving item is discarded if retaining it would cause the frequency of item type arrivals[i] to exceed m within the sliding window of the most recent w days (from day max⁡(0,i−w+1)\max(0, i - w + 1) to day i), considering only accepted arrivals. Otherwise, the item is accepted.

Return the total number of arrivals that must be discarded.

Constraints:

  • 1≤1 \leq arrivals.length ≤105\leq 10^5

  • 1≤1 \leq arrivals[i] ≤105\leq 10^5

  • 1≤1 \leq w ≤\leq arrivals.length

  • 1≤1 \leq m ≤\leq w

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Discards to Balance Inventory

med
30 min
Try to solve the Minimum Discards to Balance Inventory problem.

Statement

You are given an integer array arrivals, where arrivals[i] represents the type of item that arrives on day i, and two integers w and m.

Items arrive sequentially from day 00 to day arrivals.length −1- 1. For each day i, an arriving item is discarded if retaining it would cause the frequency of item type arrivals[i] to exceed m within the sliding window of the most recent w days (from day max⁡(0,i−w+1)\max(0, i - w + 1) to day i), considering only accepted arrivals. Otherwise, the item is accepted.

Return the total number of arrivals that must be discarded.

Constraints:

  • 1≤1 \leq arrivals.length ≤105\leq 10^5

  • 1≤1 \leq arrivals[i] ≤105\leq 10^5

  • 1≤1 \leq w ≤\leq arrivals.length

  • 1≤1 \leq m ≤\leq w