At a regional distribution center, floor staff scan a handheld terminal every time they touch a pallet. Each scan records one of four actions: scanning the pallet in, moving it, placing it on hold, or flagging it for an exception. Whenever a pallet is flagged, the terminal also records a lowercase exception code describing the problem (for example damaged, expired, or mislabeled); for every other action the terminal just records the placeholder NONE. Every night the floor manager audits one specific day and wants to know, for that day alone, how many distinct pallets were flagged under each exception code.
n, the number of log entries, and a string auditDate (format YYYY-MM-DD) — the day being audited.n lines contains four space-separated values: palletId (an integer), date (format YYYY-MM-DD), action (one of scan, move, hold, flag), and code. When action is flag, code is a lowercase exception code; for every other action code is the literal string NONE.Print one line for every exception code that has at least one pallet flagged under it on auditDate, formatted as code count, where count is the number of distinct pallet IDs flagged with that code on that date (a pallet flagged with the same code more than once that day still counts once). Sort the lines by code in ascending lexicographic order. If no pallet was flagged on auditDate, print nothing.
YYYY-MM-DDaction is flag, code consists of 1 to 20 lowercase English lettersExample 1
Input
7 2021-01-06 101 2021-01-05 flag damaged 101 2021-01-06 flag damaged 102 2021-01-06 flag damaged 103 2021-01-06 scan NONE 104 2021-01-06 flag expired 104 2021-01-06 flag expired 105 2021-01-07 flag damaged
Expected
damaged 2 expired 1
Explanation
The audit date is 2021-01-06. On that date, pallets 101 and 102 were flagged `damaged` (2 distinct pallets), and pallet 104 was flagged `expired` twice but counts once (1 distinct pallet). Pallet 101's flag on 2021-01-05, pallet 105's flag on 2021-01-07, and pallet 103's plain `scan` are all outside the audited day's flag count and are ignored. Sorted alphabetically, the output is `damaged 2` then `expired 1`.
Example 2
Input
3 2022-03-10 201 2022-03-10 scan NONE 201 2022-03-11 flag mislabeled 202 2022-03-10 move NONE
Expected
(empty)Explanation
The audit date is 2022-03-10. The only entries on that date are a `scan` and a `move`, neither of which is a flag; the one `flag` entry in the log is dated 2022-03-11, a different day. Since no pallet was flagged on the audited date, the program prints nothing.
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 →