#C6552. Consistency Score in Shopping Behavior
Consistency Score in Shopping Behavior
Consistency Score in Shopping Behavior
A customer’s shopping behavior can often be analyzed by examining the frequency at which they purchase items in various categories. In this problem, you are given a list representing the purchase history of a customer. Each integer in the list represents an item category. Your task is to compute the consistency score for the customer’s shopping behavior.
The consistency score is defined as follows:
- If the purchase history is empty, the score is 0.
- Otherwise, count the frequency of each distinct item category.
- Compute the average frequency, ( \mu = \frac{n}{m} ) where ( n ) is the total number of purchases and ( m ) is the number of distinct categories. Round the average (\mu) to the nearest integer (using standard rounding rules).
- The consistency score is the number of categories whose purchase frequency exactly equals this rounded value.
For example, consider the purchase history [1, 1, 2, 2, 3]:
- Frequency: category 1 appears 2 times, category 2 appears 2 times, and category 3 appears 1 time.
- Average frequency = ( \frac{5}{3} \approx 1.67 ), which rounds to 2.
- Categories with frequency 2: 2 categories (category 1 and 2). So, the consistency score is 2.
You will be provided multiple test cases. The input for each test case starts with an integer denoting the number of purchases, followed by the purchased item categories. Process each test case and print the consistency score on a new line.
inputFormat
The input starts with an integer (T) representing the number of test cases. For each test case, the first integer denotes (n), the number of purchases, followed by (n) integers indicating the item categories purchased. All input is provided via standard input (stdin).
outputFormat
For each test case, output a single integer — the consistency score — on a new line. All output should be written to standard output (stdout).## sample
2
5 1 1 2 2 3
6 4 4 4 5 5 6
2
1
</p>