Trains the technique from
LeetCode 1838Frequency of the Most Frequent ElementThis 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.
Example 1
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
Both microns go on the plate at 2, lifting it to 4 so that both plates measure 4.
Example 3
All four plates already measure 7, so the batch is complete without spraying anything.
Example 4
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.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_matched_plates(plates: list[int], coating: int) -> int:public int maxMatchedPlates(int[] plates, int coating)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.