AmazonOA #320
Order Layout
Estimated MediumJudge-ready
Topics (AI-labelled)StringsSimulation
Configuration entries are separated by vertical bars; each entry is a four-digit decimal sequence number immediately followed by a non-empty configuration value. A valid layout must have sequence numbers that are exactly 1..number of entries, with no duplicates or gaps, and configuration values that contain only ASCII letters and digits and are all distinct. Output the configuration values in sequence-number order; if any check fails, output ["Invalid configuration"]. Duplicate values may appear in the input being validated, but such input is invalid.
Input
One line containing layout. In the original statement the bound on orders and sequence numbers is 1..9999; the input may have missing or duplicate numbers. For invalid inputs, this site also allows 0..9999 separated entries with entry length 0..104, made of printable ASCII characters without whitespace; this site adds 1..100 characters for valid configuration values. The four-digit sequence number must consist of ASCII digits. Empty input is also an invalid layout to be validated.
Output
If the layout is valid, output a compact JSON array of strings ordered by sequence number; otherwise output ["Invalid configuration"].
Example 1
Input:
0002BB|0001AA
Output:
["AA","BB"]
Example 2
Input:
0001A|0002A
Output:
["Invalid configuration"]
Example 3
Input:
0002B|0002C
Output:
["Invalid configuration"]
Example notes
The outputs are ["AA","BB"], ["Invalid configuration"] and ["Invalid configuration"]. The second example openly shows the uniqueness check on configuration values that the source code omits; duplicate values cannot be accepted just because their sequence numbers differ.
Editorial
Loading solution…