All problems
0205MediumArrayBinary SearchGreedySliding WindowSortingPrefix Sum

Plates at One Thickness

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1838Frequency of the Most Frequent Element

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A plating shop builds press plates up to size with a spray gun. plates gives the current thickness of each plate in microns, in no particular order, and coating is how many microns of spray are left in the tank altogether.

One micron of spray raises one plate by one micron and draws one micron from the tank. You may spray any plate as often as you like, in any order, but spray can never be stripped back off, so no plate ever gets thinner. You are not obliged to empty the tank.

The press only accepts a batch of plates that all measure exactly the same. Return the largest number of plates that can be brought to one common thickness.

Examples

Example 1

Input
plates = [9, 4, 8, 8, 6], coating = 4
Output
3

Spray 2 microns onto the plate at 6 to bring it to 8. Together with the two plates already at 8 that makes three plates measuring 8, with 2 microns still in the tank.

Example 2

Input
plates = [2, 4], coating = 2
Output
2

Both microns go on the plate at 2, lifting it to 4 so that both plates measure 4.

Example 3

Input
plates = [7, 7, 7, 7], coating = 1
Output
4

All four plates already measure 7, so the batch is complete without spraying anything.

Example 4

Input
plates = [1, 2, 3, 4, 100], coating = 2
Output
2

Spraying 2 microns onto the plate at 2 takes it to 4, which matches the plate already at 4, giving two plates at the same measure.

Constraints

  • 1 <= plates.length <= 10^5
  • 1 <= plates[i] <= 10^5
  • 1 <= coating <= 10^5

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def max_matched_plates(plates: list[int], coating: int) -> int:
Java
public int maxMatchedPlates(int[] plates, int coating)
September 7
Apply