A team has a command log but cannot easily see which actions dominate it. A short frequency ranking turns repeated names into an understandable summary. Ties need a clear rule so two runs give the same answer.
Add hot to return the K most frequent command names with their counts. Keep each input trace independent. This is history analysis, not live monitoring or an execution-speed optimization.
Input: One or more hot K name... command lines, optionally followed by exit. K is positive and each hot command supplies at least one name.
Output: Print up to K name:count pairs separated by single spaces. Higher counts come first; tied names are alphabetical.
Input:
hot 2 echo cd echo pwd echo cd
Output:
echo:3 cd:2
Explanation: echo appears three times and cd twice. K is 2, so the lower-count pwd does not appear in the result.
Input:
hot 2 pwd cd pwd cd ls
Output:
cd:2 pwd:2
Explanation: cd and pwd both appear twice. Alphabetical order puts cd first even though pwd occurs first in the input.
Input:
hot 1 fast-eval fast-eval fast-eval
Output:
fast-eval:3
Explanation: Repeated names become one ranked entry with a count of 3; K counts distinct names, not occurrences.
Input:
hot 5 echo pwd
Output:
echo:1 pwd:1
Explanation: There are only two distinct names. Asking for five returns both rather than inventing extra entries.
Input:
hot 3 run echo which echo run echo which pwd
Output:
echo:3 run:2 which:2
Explanation: echo leads with 3. run and which tie at 2, so run comes first alphabetically; pwd falls outside the top three.
Paste this into Custom Input and run your solution.
hot 2 pwd echo pwd echo
Why does echo come first when pwd appears first in the input?
Expected output:
echo:2 pwd:2
Both counts are 2, so the alphabetical tie rule decides their order. First appearance is not the tie-breaker.
What should your sort compare when two names have the same frequency?
This is a fixed input trace, not live monitoring. You can now explain command dispatch, controlled program results, job states, pipelines, and data summaries. These exercises model useful mechanisms; finishing them does not produce a production-ready Unix shell.
Try an extra input of your own and explain why your solution works before exploring another system.
echo:3 cd:2