#K73417. Top Three Frequent Rental Durations
Top Three Frequent Rental Durations
Top Three Frequent Rental Durations
You are given a list of rental durations (integers). Your task is to determine the three most frequent rental durations. In case of a tie in frequency, the smaller rental duration should come first.
If there are fewer than three unique rental durations, output all of them following the same rule.
Note: The frequency is determined by the number of occurrences in the input list. The answer should be output in one line with each duration separated by a space.
For example:
- For the input list
[3, 3, 3, 1, 2, 2, 4]
, the output is3 2 1
because 3 appears the most, then 2 and 1 (even though 4 appears once as well, the smaller number between 1 and 4 comes first).
inputFormat
The first line contains an integer n, representing the number of rental durations. The second line contains n space-separated integers representing the rental durations.
Example:
7 3 3 3 1 2 2 4
outputFormat
Output the top three most frequent rental durations (or fewer if there are less than three unique durations) in one line, separated by a single space.
Example:
3 2 1## sample
7
3 3 3 1 2 2 4
3 2 1