Log Analyzer: Busiest Service in a Rolling Window
Updated
Problem statement
You are given the request logs of several services. Log i says that the service named services[i] received one request at second timestamps[i]. The logs can be in any order, and a service can receive several requests in the same second.
A window of t seconds covers every time from some second s up to s + t, including both ends. So two requests at times a <= b can be in the same window exactly when b - a <= t.
For each service, find the largest number of its own requests that fit in one window. A service is busiest if no other service has a larger number.
Return one row [name, count] for every busiest service, where count is that largest number written as a decimal string. If several services tie, return all of them, with the rows sorted by service name in the usual string order (so "AB" comes before "B").
Function
busiestServices(timestamps: int[], services: String[], t: int) → String[][]Examples
Example 1
timestamps = [10,40,100,200,260,280,310,210]services = ["A","B","A","A","B","A","B","A"]t = 300return = [["A","5"]]- The logs are not in time order. Sorted, service
"A"has requests at10,100,200,210and280, and service"B"at40,260and310. - The window from
10to310holds all5requests of"A", because280 - 10 = 270 <= 300. - All
3requests of"B"also fit in one window (310 - 40 = 270), but3 < 5. - The busiest service is
"A"with5requests.
Example 2
timestamps = [10,20,30,40,50,60,70]services = ["A","B","A","B","A","B","A"]t = 60return = [["A","4"]]- Service
"A"has requests at10,30,50and70. The window from10to70is exactly60seconds long and includes both ends, so it holds all4. - Service
"B"has requests at20,40and60, so its best window holds3. - The answer is
"A"with4requests.
Example 3
timestamps = [100,100,100,100,110,110]services = ["A","A","B","B","B","A"]t = 10return = [["A","3"],["B","3"]]- Service
"A"has requests at100,100and110. Two requests at the same second count separately, and110 - 100 = 10, so one window holds all3. - Service
"B"has the same times, so it also reaches3. - Both services tie, so both are returned, sorted by name:
"A"first, then"B".
Constraints
1 <= timestamps.length <= 2 * 10^4services.length == timestamps.length0 <= timestamps[i] <= 10^91 <= t <= 10^9services[i]has 1 to 10 characters, and each one is an uppercase English letter.
More ByteDance Phone Screen questions
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
- Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Number of Events That Can Be AttendedPHONE SCREEN · Seen Nov 2026
- Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Meeting RoomsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Message Event AggregationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Top K Best-Selling Products in the Last N DaysAmazon · ONSITE INTERVIEW
- Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Count Redundant File BackupsGoldman Sachs · OAGoldman Sachs interview questions