The core idea clicked pretty fast: for each driver, binary search their sorted records to find entries that fall within the window, then count if at least one exists.
For each driver, use binary search on their sorted timestamps to find the first record within the 24-hour window before t, then check if that record indicates they were online. Count drivers where such a record exists. This yields O(D log N) time, where D is the number of drivers and N is the average number of records per driver.
Pro tip: Clarify the data format: if each record includes an online/offline status, you need to check if the driver was online at any point, not just if they had any record. Also, mention that if the number of drivers is huge, you could optimize further by precomputing or using a segment tree, but the binary search approach is simple and efficient for most cases.
Confirm that each driver has a chronologically sorted list of delivery records, each with a timestamp and possibly an online status. The goal is to count distinct drivers who were online at any point in [t-24h, t].
Compute the start time as t minus 24 hours. For each driver, you need to find if there is any record with timestamp >= start and <= t that indicates online.
For each driver's sorted list, use binary search to find the first record with timestamp >= start. If such a record exists and its timestamp <= t and it indicates online, then the driver was online.
Increment a counter for each driver meeting the condition. Consider edge cases: no records in window, records exactly at boundaries, and drivers with no records at all.
Explain that binary search per driver takes O(log N) time, so total is O(D log N), where D is number of drivers and N is average records per driver. This is efficient compared to scanning all records.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.