Dsa
Sorting
Easy
Product Popularity
You are tasked with determining the most popular products sold in a store based on sales records. Each record contains a product ID. Your goal is to output a list of product IDs sorted first by their sales count in descending order and then by product ID in ascending order if counts are equal.
Input:
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of sales records.
The next N lines each contain a single integer representing the product ID (1 ≤ product ID ≤ 10000).
Output:
Print the sorted list of product IDs in the format [product1, product2, ...].
Example:
Input:
5
100
101
100
102
101
Output:
[100, 101, 102]
Key concepts
sortingfrequencycollections
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now