A logistics operator tracks a fleet of delivery drones. After each flight, every drone uploads a short diagnostic report: an identifier, a call name, and a list of diagnostic codes produced by its onboard sensors. The maintenance team wants to build a watchlist of every drone that reported at least one diagnostic code beginning with a specific alert prefix, so a technician can inspect it before the drone flies again.
Given the fleet's reports and an alert prefix, output the identifier and call name of every drone that has at least one diagnostic code starting with that prefix (a code counts as a match as soon as its leading characters equal the prefix, even if the code continues further — e.g. code OVH104 matches prefix OVH1). Preserve the order in which drones appear in the input.
n, the number of drones.n lines each describe one drone: an identifier, a call name, an integer k (the number of diagnostic codes that drone reported), and then k diagnostic codes — all separated by single spaces.m, the number of drones on the watchlist.m lines: for each flagged drone, in the same order it appeared in the input, print its identifier and call name separated by a single space.Example 1
Input
3 OVH1 101 DRN_A 2 OVH104 GPS02 102 DRN_B 1 BAT7 103 DRN_C 3 OVH204 OVH1X ROT3
Expected
2 101 DRN_A 103 DRN_C
Explanation
Drone 101 reports code OVH104, which begins with OVH1, so it is flagged. Drone 102's only code, BAT7, does not begin with OVH1, so it is not flagged. Drone 103 reports OVH204 (begins with OVH2, no match) and OVH1X (begins with OVH1, a match), so it is flagged too. The watchlist has 2 drones, listed in their original order: 101 DRN_A then 103 DRN_C.
Example 2
Input
2 ZED 5 UNIT5 0 6 UNIT6 2 ERR90 ERR8
Expected
0
Explanation
Drone 5 reported zero diagnostic codes, so it can never match. Drone 6's codes are ERR90 and ERR8, neither of which begins with ZED. No drone qualifies, so the watchlist is empty and only the count 0 is printed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →