An arcade's coin-op machines are each stamped with a numeric machine ID. A maintenance log records, in order, the ID of the machine that fired every time it dispensed a token during a single business day. The shift manager suspects two specific machines are behaving inconsistently with each other and wants to flag the pair that is easiest to justify to a technician: the lexicographically smallest pair of distinct machine IDs appearing anywhere in the log whose total dispense counts for the day differ from one another.
Formally, count how many times each distinct machine ID occurs in the log. Among all pairs of distinct IDs (a, b) with a < b such that the count of a differs from the count of b, find the pair that is smallest when compared first by a, then by b, and report it. If every pair of distinct IDs has matching counts (including when at most one distinct ID appears in the log), report that no such pair exists.
Example 1
Input
5 4 2 4 2 5
Expected
2 5
Explanation
Machine 4 fires twice, machine 2 fires twice, and machine 5 fires once. Checking distinct IDs in increasing order: the pair (2, 4) both have count 2, so it is not a mismatch; the next pair (2, 5) has counts 2 and 1, which differ. So the lexicographically smallest mismatched pair is 2 5.
Example 2
Input
3 7 7 7
Expected
-1 -1
Explanation
Only one distinct machine ID (7) appears in the log, so there is no second distinct ID to compare its count against. No mismatched pair can exist, so the output is -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 →