A warehouse control system stores a number in each indexed bin. Starting with all bins empty, it processes q operations, each one of:
SET index number — place number into bin index, replacing whatever was there.FIND number — report the smallest bin index currently holding number, or -1 if no bin currently holds it.Line 1: an integer q.
Next q lines: SET index number or FIND number.
For each FIND operation, in order, print the smallest matching index, or -1.
Example 1
Input
5 FIND 10 SET 2 10 SET 5 10 FIND 10 SET 2 20
Expected
-1 2
Explanation
No bin holds 10 at first, so FIND 10 is -1. After bins 2 and 5 hold 10, the smallest index is 2.
Example 2
Input
6 SET 4 7 SET 1 7 FIND 7 SET 1 8 FIND 7 FIND 8
Expected
1 4 1
Explanation
Bins 4 and 1 hold 7, so FIND 7 is 1. After bin 1 changes to 8, only bin 4 holds 7 (FIND 7 = 4) and bin 1 holds 8 (FIND 8 = 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 →