Amazon Interview
How to parse a binary byte-array with 1-byte Type (0-255), 1-byte Length (n), n-byte Value, where Value constraints vary by Type (e.g., Type 0 → 0-9)?
The Type field can have values from 0-3.
The Value field can have values from 0-255.
For each unique Type (0-3), a distinct print method must be called to print the Type and Value fields. This means there should be four different methods, one for each Type.
The method associated with a Type should be called efficiently.
Additional Considerations:
Proper error handling and bounds checking must be implemented.
If the Type field were expanded to 0-255, how would the code architecture change?
If the binary data contained three fields—1-byte Type, 1-byte Length (n), and an n-byte Value—how would the architecture adapt?
If Value constraints varied based on Type (e.g., Type 0 allows values 0-9, Type 1 allows 10-19), how should the design be structured?