#C14345. Counting Occurrences and Minimum Frequency Finder
Counting Occurrences and Minimum Frequency Finder
Counting Occurrences and Minimum Frequency Finder
You are given a list of integers. Your task is to count the number of occurrences (frequency) of each distinct integer and then determine the integer that appears the least number of times. In case of a tie among several integers (i.e. more than one integer with the same minimum frequency), output the smallest integer among them.
If the list is empty, simply output an empty dictionary and None
for the least frequent integer.
Note: The frequency dictionary should be printed in the order of increasing integers. The dictionary should be formatted as follows:
{a: p, b: q, ...}
For example, if the input is [4, 2, 1, 3, 2, 4, 1, 2, 4, 4, 5]
, the frequency dictionary is {1: 2, 2: 3, 3: 1, 4: 4, 5: 1} and since both 3 and 5 occur once, you should output 3 since it is the smallest.
inputFormat
The input is given via stdin and has the following format:
- The first line contains an integer
n
which denotes the number of elements in the list. - If
n > 0
, the second line containsn
space-separated integers representing the list.
If n
is 0, the list is considered empty.
outputFormat
The output should be printed to stdout and must consist of two lines:
- The first line is the frequency dictionary with keys sorted in increasing order. The format should be exactly as shown, e.g.
{1: 2, 2: 3, 3: 1, 4: 4, 5: 1}
. - The second line is the integer with the least frequency. If there is a tie, output the smallest integer among them. For an empty list, output
None
on the second line.
11
4 2 1 3 2 4 1 2 4 4 5
{1: 2, 2: 3, 3: 1, 4: 4, 5: 1}
3
</p>