Find Most Frequently Purchased Products
The manager of a grocery store tagGrocery wishes to determine which products are most popular with his customers (i.e. which products they purchase most frequently). The manager selects N customers who purchase a shopping bag of items containing M products, each labeled with a productID. By analyzing these M products, the manager wishes to find the productIDs of the distinct products that get purchased most frequently by at least K(given) customers.
Write an algorithm to help the manager find the productIDs of the products that are most frequently purchased by the K customers.
Input
Output
Print space-separated integers representing the lexicographically sorted productIDs of the products that are most frequently purchased by the K customers.
Constraints
1 ≤ tag_row ≤ 10^3
1 ≤ tag_col ≤ 10^3
1 ≤ K input ≤ tag_row
0 ≤ tag[0], tag[1], ......., tag[N-1] ≤ 10^9