FastPrepMessages in an Inclusive Timestamp Range
Problems/Messages in an Inclusive Timestamp Range

Messages in an Inclusive Timestamp Range

Attentive logoAttentive● EasyFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report defines sorted in-memory logs, inclusive bounds, duplicate timestamps, and handwritten binary search. Parallel arrays and safe bounds are specified for practice; the judged task matches at about 98%.

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.
  • timestamps is sorted in nondecreasing order.
  • -10^18 <= timestamps[i], start, end <= 10^18.
  • start <= end.
  • Each message has length at most 200.

More Attentive problems

  • Lisp Expression ParserONSITE INTERVIEW · Seen Sep 2026
  • Remove Adjacent Duplicates in String IIPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
All Attentive interview questionsSee Attentive hiring insights
Saved
class Solution {
    public String[] messagesInRange(long[] timestamps, String[] messages, long start, long end) {
        // Write your code here.
    }
}
Checking account…