Trains the technique from
LeetCode 692Top K Frequent WordsThis 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 repair bay logs the code of every part it lifts off the shelf. The log arrives as draws, the part codes in the order they were lifted, one entry per part, so a code drawn four times appears four times.
Return the k codes drawn the most, listed from the most drawn down to the least drawn among them.
Codes drawn the same number of times are listed in dictionary order, which keeps the answer unambiguous. Dictionary order compares two codes letter by letter from the front and settles them at the first letter that differs; when one code is a prefix of the other, the shorter code comes first.
Example 1
The bay drew ratchet three times, clamp twice and shim once, so the two most drawn codes are ratchet then clamp.
Example 2
Both shim and bolt were drawn twice, so they are listed in dictionary order, which puts bolt first; nut was drawn once and misses out.
Example 3
Codes ab and b were each drawn twice and ab is earlier in dictionary order, since a comes before b at the first letter. Code cd was drawn once and takes the last place.
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 busiest_codes(draws: list[str], k: int) -> list[str]:public List<String> busiestCodes(String[] draws, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.