LRU cache simulation: Simulate an LRU cache. put stores or replaces a key and get returns its value or -1; accessing or writing a key makes it most recently used. Return the results of get operations.
Input: A JSON object { "capacity": number, "operations": { "type": "get"|"put", "key": string, "value"?: number }[] }.
Output: A JSON number[] containing get results in operation order.
Constraints:
- 0 <= operations.length <= 100000
- capacity is a non-negative integer
- get and put should be O(1) expected time
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: HARD. Variant: 24. Favor a pragmatic solution that is easy to ship, read, and adapt.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is