Back to problems

Count Events Before Timestamp

Algorithm · Snapchat · Easy

You receive event timestamps in ascending order and must determine how many events happened strictly earlier than a specified query time. The input consists of a sorted timestamp list together with one query timestamp. Return the number of timestamps that precede the query value. Input: Timestamp list: [2, 4, 6, 8, 10, 12, 14] Query timestamp: 9 Output: 4 The input contains at most 10^5 entries. Example The first four timestamps are less than 9, so the result is 4.

Checking your access…