Interview Questions/Coding/Packet Blueprint Assembly

Packet Blueprint Assembly

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

Medium

Packet Blueprint Assembly

A deployment blueprint is an ordered array of module ids. The warehouse stores sealed packets, and each packet is also an ordered array of module ids. Packets may be arranged in any order, but a packet cannot be split, reversed, or reused. The final blueprint must be formed by concatenating selected packets exactly. Each packet has a distinct first module id. Input Format: You are given an array target and an array packets. Output Format: Return YES if target can be assembled exactly from the packets, otherwise return NO.

Examples

Example 1
Input:
target = [85]
packets = [[85]]
Output:
YES

Explanation: Scanning target [85] uses packets [85] without mismatch. Therefore the output is YES.

Approach hint

Look for the state that actually matters after each operation.

Common mistake

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

solution.cpp