Interview Questions/Coding/Magic Batch Code Validator

Magic Batch Code Validator

Preview mode. Log in to edit, run, submit, and save progress.

Easy

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

Example 1
Input:
1
1141144
Output:
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 the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp