An online auction platform logs every bid submitted for a single lot, in the exact order the bids arrived. Bids are integers (a bid can be negative if it represents a rebate credit applied against a reserve price). The platform wants to convert each raw bid amount into a compact rank number: the lowest bid amount present becomes rank 1, the next distinct amount (however many bids share it) becomes rank 2, and so on, so that ranks are as small as possible while two equal bid amounts always receive the exact same rank.
Given the bids in their original arrival order, print the corresponding rank for each bid, preserving that same order.
Print n space-separated integers on a single line: the rank of each bid, in the same order the bids were given.
Example 1
Input
4 40 10 20 30
Expected
4 1 2 3
Explanation
The distinct bid amounts sorted ascending are 10 (rank 1), 20 (rank 2), 30 (rank 3), and 40 (rank 4). Replacing each bid in its original arrival order (40, 10, 20, 30) with its rank gives "4 1 2 3".
Example 2
Input
3 100 100 100
Expected
1 1 1
Explanation
All three bids share the single distinct amount 100, which becomes rank 1, so every position in the output is 1: "1 1 1".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →