A transit operator is testing a maintenance turnstile that unlocks only for a valid 3-digit even access code. A technician has a tray holding n numbered chips, each stamped with a single digit from 0 to 9 (the same digit may appear on more than one chip). To build a candidate code, the technician picks exactly 3 chips from the tray -- each physical chip can be used at most once within a single code -- and arranges them left to right to form a 3-digit number. A code is accepted only if it has no leading zero and its value is even. Determine every distinct code value that can be assembled from the tray in this way.
Print every distinct achievable code, sorted in ascending order, space-separated on a single line. If no code can be assembled, print an empty line.
Example 1
Input
4 2 1 3 0
Expected
102 120 130 132 210 230 302 310 312 320
Explanation
The tray holds chips {2,1,3,0}. Arranging three of these four chips so the leading chip is nonzero and the last chip is even yields exactly the values 102, 120, 130, 132, 210, 230, 302, 310, 312, 320 -- every other ordering either starts with 0 or ends in an odd digit, so no other code is achievable.
Example 2
Input
5 2 2 8 8 2
Expected
222 228 282 288 822 828 882
Explanation
The tray holds three chips showing 2 and two chips showing 8. Since 2 appears three times, an all-2 code (222) is buildable; since only two chips show 8, any code needs at most two 8-chips, giving 228, 282, 288, 822, 828, and 882 as well. A code like 888 is impossible (only two 8-chips exist), so exactly these seven values are achievable.
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 →