Messages in an Inclusive Timestamp Range
Problem statement
In-memory logs are stored in nondecreasing timestamp order. Parallel arrays timestamps and messages describe each log entry.
Given inclusive bounds start and end, return the messages for every entry whose timestamp is in [start, end]. Preserve input order and retain entries with duplicate timestamps.
Function
messagesInRange(timestamps: long[], messages: String[], start: long, end: long) → String[]Examples
Example 1
timestamps = [1,2,2,5,8]messages = ["a","b","c","d","e"]start = 2end = 5return = ["b","c","d"]Both entries at timestamp 2 and the entry at timestamp 5 lie inside the inclusive range.
Example 2
timestamps = [3,7,9]messages = ["x","y","z"]start = 10end = 12return = []No timestamp lies in the requested range.
Constraints
0 <= timestamps.length == messages.length <= 200000.timestampsis sorted in nondecreasing order.-10^18 <= timestamps[i], start, end <= 10^18.start <= end.- Each message has length at most
200.