Magic Batch Code Validator
Preview mode. Log in to edit, run, submit, and save progress.
Magic Batch Code Validator
A batch scanner accepts access codes made only by concatenating approved fragments. The allowed fragments are 1, 14, and 144. A code is valid only if the entire string can be split into these fragments with no leftover characters and no other digit pattern. Decide whether each submitted code passes the scanner. Input Format: The first line contains t, the number of test cases. Each test case contains one digit string. Output Format: For each test case, print YES if the code is valid, otherwise print NO.
Examples
1 1141144
YES
Explanation: The code can be read as 1, 14, 1, and 144, so every digit belongs to an approved fragment.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
1
1141144YES