← 返回 databricks 的题目列表In-memory KV Store - Calculate AVG LOAD TIME
类型:online_judge
Please design an in-memory key-value store (KV Store) that supports basic PUT and GET operations. Additionally, implement a function that can query the average number of PUT and GET operations within a specified time range.
Requirements:
The system should support PUT(key, value) operations to store values for specified keys.
The system should support GET(key) operations to return the values for specified keys.
The system should support querying the average number of PUT and GET operations per second over a given time interval.
Data should only be saved for operations within the last year.
Example:
Suppose there were 100 GET operations and 200 PUT operations in the last 10 minutes, the system should return:
Average GET operations per second: 100 / 600 = 0.1667
Average PUT operations per second: 200 / 600 = 0.3333
Please provide the necessary data structures and function interfaces, and implement the code to achieve the above functionality.
Example
Input
commands = ['put', 'get', 'average_operations']
values = [["key", "value"], ["key"], [600]]