Barcode Scanner
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 system, and then needs to present the configurations in the correct order. The encoded configuration string is a series of pairs separated by |. The ordinal index valid is a 4 digit numeric prefixed with 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 value in the order required to successfully configure the barcode scanner.
Validation conditions:
All configurations must be seperated by | character Configurations cannot skip a number in the ordering. If there are three configuraiton strings, there must be a 1, 2 and 3 index Configuration values are alphanumeric and may contain no other characters Configuration value length is exactly 10 characters Ordinal indices may not repeat, for example there cannot be two occurrences of number 1 Each configuration value is unique, configurations do not repeat. 0000 is not a valid ordinal index If a Configuration string is invalid return [“Invalid configuration”]
Example
configuration = “0002f7c22e7904|000176a3a4d214|000305d29f4a4b” Output: [ “76a3a4d214”, “f7c22e7904”, “05d29f4a4b” ]
Here is one approach to validate the configuration string and return the configurations in order:
|
|
The key steps are:
- Validate format using regex
- Extract configurations
- Validate index and value per configuration
- Check no duplicates
- Sort configurations by index
This validates the overall format, each configuration, and ordering to ensure a valid configuration string.