Frequency of the Most Frequent Element
Real-world version: Plates at One ThicknessThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_matched_plates(plates: list[int], coating: int) -> int:public int maxMatchedPlates(int[] plates, int coating)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 18 test cases: 18 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Maximum Coins From K Consecutive BagsReal-world version: Richest Run of Consecutive BinsMedium
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy
- Maximize the Minimum Powered CityReal-world version: Lift the Weakest Relay StopHard
- Minimum Cost to Make Array EqualReal-world version: Regrading the Survey PegsHard