Vercel may need to report how many requests a deployment received during a specified time window. Maintain hit timestamps for a Vercel deployment and support efficient range-count queries.
Implement two functions:
record_hit(hit_times, timestamp): Add one hit timestamp while keeping hit_times sorted.count_hits(hit_times, start, end): Return the number of hits whose timestamps are between start and end, inclusive.The input timestamps are integer seconds. A timestamp may occur multiple times, and every hit must be counted. The query function must not modify the list.
hit_times is a sorted list of integers representing recorded hit timestamps.timestamp, start, and end are integers.record_hit returns the updated list after inserting the timestamp in sorted order.count_hits returns an integer count.start <= end.def count_hits(hit_times, start, end):