A barcode scanner can be configured by scanning a series of barcodes in the correct order. Barcode configurations are encoded into a single string and stored as a blob in the backend system. The client requests the configuration from the backend configuration service, and then needs to present the configurations in the correct order. The encoded configuration string is a series of <ordinal-index>/<configuration>
pairs separated by '|'. The ordinal index value is a 4 digit numeric prefix within zeros. For example, the first configuration will be represented as 0001.
The goals are to 1) validate the configuration string and 2) provide the configuration client the configuration values in the order required to successfully configure the barcode scanner.
Validation conditions
If a configuration string is not valid, return ["Invalid configuration"]
.
Function Description
Complete the function orderedConfiguration
in the editor.
orderedConfiguration
has the following parameters:
str configuration
: the encoded configuration stringReturns
str configuration[]
: an array of configurations in the correct orderExample 1:
Input: configuration = "0001LAJ5KBX9H8|0003UKURNK403F|0002MO6K1Z9WFA|0004OWRXZFMS2C"
Output: ["LAJ5KBX9H8", "MO6K1Z9WFA", "UKURNK403F", "OWRXZFMS2C"]
Explanation:The value "LAJ5KBX9H8" is prefixed with an order value of "0001", so it is listed first. Even though "MO6K1Z9WFA" appears third in the string, it is prefixed with "0002" so it is rereturned second. "UKURNK403F" appears second in the configuration string, but is prefixed with "0003" so is listed third. Lastly, "OWRXZFMS2C" is prefixed with 0004 so is listed fourth.
Example 2:
Input: configuration = "000533B8XLD2EZ|0001DJ2M2JBZZR|0002Y9YK0A7MYO|0004IKDJCAPG5Q|0003IBHMH59SBO"
Output: ["DJ2M2JBZZR", "Y9YK0A7MYO", "IBHMH59SBO", "IKDJCAPG5Q", "33B8XLD2EZ"]
Explanation:No explanation for now
Example 3:
Input: configuration = "0002f7c22e7904|000176a3a4d214|000305d29f4a4b"
Output: ["76a3a4d214", "f7c22e7904", "05d29f4a4b"]
Explanation:Based on the 'order' value, the expected output is: [ "76a3a4d214", #0001 "f7c22e7904", #0002 "05d29f4a4b" #0003 ]
Example 4:
Input: configuration = "0002f7c22e7904|000176a3a4d214|000205d29f4a4b"
Output: ["Invalid configuration"]
Explanation:configuration string constains two indices for "0002", so the expected output is ["Invalid configuration"].
- 1 ≤ orders ≤ 9999
- 1 ≤ orders(configuration) ≤ 9999
- Order values may not be unique or complete
- Configuration values are not always unique, the same configuration may appear in multiple configuration steps
input:
output: