Practice
Dice Roll Frequency Table
2025/Oct/Nov·Variant 2·Q10·[15 marks]
HARDArrays
Read how many rolls were recorded (N), then N integers between 1 and 6. Count how many times each face appeared, sort those six faces into descending order of frequency (bubble sort; leave equal frequencies in their original numeric order), and output each face, its count, and its relative frequency rounded to 4 decimal places.
Input: N, then N dice values.
Output: Six lines <face> <count> <frequency> in descending count order.
Example:
Input: 10
1
1
1
2
2
3
4
5
6
6
Output: 1 3 0.3
2 2 0.2
6 2 0.2
3 1 0.1
4 1 0.1
5 1 0.1
Sample Test Cases
Test 1: Mixed frequencies
Inputs: 10, 1, 1, 1, 2, 2, 3, 4, 5, 6, 6
Expected: 1 3 0.3
2 2 0.2
6 2 0.2
3 1 0.1
4 1 0.1
5 1 0.1
Test 2: Every roll is a six
Inputs: 6, 6, 6, 6, 6, 6, 6
Expected: 6 6 1
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0