#K59692. Most Popular Product
Most Popular Product
Most Popular Product
You are given an integer (T) representing the number of test cases. For each test case, an integer (N) is provided, followed by (N) space-separated strings which represent the favorite products chosen by customers. Your task is to determine the most popular product for each test case. In the event of a tie (i.e. when two or more products have the same maximum frequency), choose the product that is lexicographically smallest.
The lexicographical order follows the standard dictionary order. Use the following hint when comparing two strings (a) and (b):
[ \text{if } a < b \text{ then } a \text{ comes before } b ]
Good luck!
inputFormat
The first line of input contains an integer (T), the number of test cases. Each test case consists of two lines:
- The first line contains an integer (N), the number of customers.
- The second line contains (N) space-separated strings representing the product names.
outputFormat
For each test case, output a single line containing the most popular product. If there is a tie, output the lexicographically smallest product among those tied.## sample
2
7
cake muffin cake pie cake muffin pie
3
bread bread pie
cake
bread
</p>