cswork / OAOpen practice workspace

AmazonOA #324

Perform Queries

Estimated EasyJudge-ready

Topics (AI-labelled)SimulationIterators

The queue starts empty. INSERT appends a package ID to the end of the queue. SHIP, if the queue holds at least 3 packages, ships the earliest 3 and returns them in that order; otherwise it returns the single-element list ["N/A"] and removes no package. Return the list of results of every SHIP; if there is no SHIP, return an empty list.

Input

The input is a compact JSON two-dimensional array whose items are ["INSERT",ID] or ["SHIP","-"]. On this site 1≤number of queries≤50000, and an ID has 0..16 Unicode characters, with spaces, empty names, duplicates and case differences allowed. Whitespace inside JSON strings must use JSON escapes, for example a space is written as \u0020, and non-ASCII characters use \uXXXX or surrogate pairs; the semantic strings are not shortened.

Output

Output a compact JSON two-dimensional array; whitespace and non-ASCII characters in strings use JSON escapes, with a space encoded as \u0020.

Example 1

Input:

[["INSERT","A"],["INSERT","B"],["SHIP","-"],["INSERT","C"],["SHIP","-"]]

Output:

[["N/A"],["A","B","C"]]

Example 2

Input:

[["INSERT","a\u0020\u0020b"],["INSERT",""],["INSERT","\ud83d\ude00"],["SHIP","-"]]

Output:

[["a\u0020\u0020b","","\ud83d\ude00"]]

Example 3

Input:

[["SHIP","-"],["INSERT","X"]]

Output:

[["N/A"]]

Example notes

The outputs are [["N/A"],["A","B","C"]]; the three packages unchanged, including an ID with a double space, an empty ID and an emoji; and [["N/A"]]. The N/ A in the original example is a display typo, and this site uses N/A throughout, as in the body.

Editorial

Loading solution…