A hardware store sells digit tiles for building padlock combination codes; each tile is stamped with a single digit from 0 to 9. A customer has a bag of N such tiles (digits may repeat, since the bag was filled from bulk stock). To build a candidate 3-digit code, the customer picks any three DIFFERENT tiles from the bag and lines them up left to right; a code is valid only if its leftmost tile is not 0 (no leading zero) and its rightmost tile is even (0, 2, 4, 6, or 8). Because tiles with the same digit look identical, different tile choices can spell the same code — such a code should only be reported once. Given the digits on all N tiles, determine every distinct valid code the customer could assemble, and list them in ascending numeric order.
Print all distinct valid 3-digit even codes (as described above) in ascending numeric order, space-separated, on a single line. If no valid code can be assembled, print an empty line.
Example 1
Input
4 4 0 4 2
Expected
204 240 244 402 404 420 424 440 442
Explanation
The bag has two 4-tiles, one 0-tile, and one 2-tile. For example, 204 uses the 2, the 0, and one 4; 244 uses the 2 and both 4-tiles (the bag has two); 440 uses both 4-tiles plus the 0. Every one of the nine listed codes needs at most one 0, at most one 2, and at most two 4's — exactly what the bag supplies — and no other nonzero-leading even code is achievable, so the output is '204 240 244 402 404 420 424 440 442' in ascending order.
Example 2
Input
3 9 9 9
Expected
(empty)Explanation
The bag holds three tiles, all digit 9. The only code assembleable from these tiles is 999, whose rightmost digit (9) is odd, so no valid even code exists — the output is an empty line.
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 →