← 返回 snowflake 的题目列表In-Memory Time-Series Database for Thermostat Temperatures
类型:online_judge
snowflake
Design a backend in-memory database for a thermostat device. The data format sent by the device is as follows: [timestamp(XXXX-XX-XX XX:XX:XX), temperature(e.g 24.6)]. The database should efficiently support the following two queries:
What is the temperature at <t1>?
Provide all temperature data from <t1> to <t2>.
Data Stream:
2023-01-01 10:01:01 24.6
2023-01-01 10:02:02 24.7
2023-01-01 11:02:00 27.6
Query:
Give me all the temperature data from 2023-01-01 10:00:00 to 2023-01-01 11:00:00
The result should be:
2023-01-01 10:01:01 24.6
2023-01-01 10:02:02 24.7
Requirements:
Define the interfaces of this database (read & write operations).
Provide the implementation.
Validate the correctness with test cases.
Example
Input
2023-01-01 10:01:01 24.6
2023-01-01 10:02:02 24.7
2023-01-01 11:02:00 27.6
2023-01-01 12:02:00 29.6
2023-01-01 10:01:01
2023-01-01 10:00:00 2023-01-01 11:00:00