A deployment manifest keeps the full version history of each key. It processes q operations, each one of:
PUT key val — append val as a new version of key. Versions of a key are numbered from 1 in the order they are put. Report the version number just assigned.GET key v — report the value stored at version v of key. It is guaranteed that version v of that key already exists.Keys and values are non-empty tokens of lowercase letters and digits.
Line 1: an integer q.
Next q lines: PUT key val or GET key v.
For every PUT (print the new version number) and every GET (print the recalled value), in order, print one value per line.
Example 1
Input
5 PUT doc a PUT doc b GET doc 1 PUT doc c GET doc 3
Expected
1 2 a 3 c
Explanation
doc gets version 1 = a (prints 1) and version 2 = b (prints 2). GET doc 1 recalls a. doc gets version 3 = c (prints 3). GET doc 3 recalls c.
Example 2
Input
4 PUT k x GET k 1 PUT k y GET k 2
Expected
1 x 2 y
Explanation
k version 1 = x (prints 1); GET k 1 recalls x. k version 2 = y (prints 2); GET k 2 recalls y.
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 →