Question: give me python code [ 7 : 1 0 PM , 8 / 2 7 / 2 0 2 4 ] Rituza: Question 1 Suppose
give me python code
: PM Rituza: Question
Suppose you are responsible for building a log server that will receive a large number of logs Each log will have a log ID and timestamp. We want to keep track of these logs but due to storage limitations we can only return up to m logs from the last hour when requested.
Problem Statement
Complete the following functions
recordLoglogld timestamp: Records a new log entry.
Each log is represented as an object with a logld and timestamp.
The logid is an identifier for each log and the timestamp is an integer in seconds representing when the log was sent.
Logs may be received out of order
The log ID is not guaranteed to be unique the same log ID can be used for different logs
getLogs Returns a comma separated string of the latest m logids from the last hour ascending by timestamp. In the event of a timestamp tie order from earliest received to latest.
o Return a string of the form "logld logld logid logid where logld is the latest timestamp log and logld is the earliest timestamp log received hour before loglds timestamp getLogCount: Returns the total number of logs received hour from the most recently stored log timestamp. In the event more than m logs have been received still return the full count of logs
Constraints
ms
q
logid is an integer
timestamp is an integer representing a timestamp in seconds
: PM Rituza: left
ALL
G
Hacker...
M
order.
COUNT: This returns the total number of logs in the last hour. We have four logs from the last hour, so it returns
RECORD : The log with ID at timestamp is recorded.
GET LOGS: At this point, the logs with ID at timestamp and ID at timestamp are more than an hour old, so they are not included. The function returns the IDs of the logs from the past hour in timestamp order.
Sample Case
Sample Input For Custom Testing
RECORD
RECORD
RECORD
RECORD
GET LOGS
COUNT
RECORD
GET LOGS
COUNT
Sample Output
Explanation
RECORD : A log with ID at timestamp is recorded.
RECORD : A log with ID at timestamp is recorded.
RECORD : A log with ID at timestamp is recorded.
RECORD : A log with ID at timestamp is recorded.
GET LOGS: With m set to the function returns the latest two log IDs received in the last hour:
COUNT: Returns the total number of logs from the last hour. At this time, there are four logs in the last hour, so it returns
RECORD : A log with ID at timestamp is recorded.
GET LOGS: Again, the function returns the latest two log IDs received in the last hour,
COUNT: Returns the total number of logs from the last hour. At this time, there are five logs in the last hour, so it returns
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
