Count Zero Request Servers
Updated
Problem statement
You are given an integer n, the number of servers (with ids 1 to n), and a 2D integer array logs, where logs[i] = [serverId, time] means that server serverId received a request at time time.
You are also given an integer x and an integer array queries. For each queries[i], count the servers that did not receive any request during the time interval [queries[i] - x, queries[i]]. Both ends of the interval are included.
Return an array arr of the same length as queries, where arr[i] is the count for queries[i].
Function
countServers(n: int, logs: int[][], x: int, queries: int[]) → int[]Examples
Example 1
n = 3logs = [[1,3],[2,6],[1,5]]x = 5queries = [10,11]return = [1,2]- Query 10 looks at
[5, 10]: servers 1 (time 5) and 2 (time 6) get requests, so only server 3 is idle. - Query 11 looks at
[6, 11]: only server 2 gets a request, so servers 1 and 3 are idle.
Example 2
n = 3logs = [[2,4],[2,1],[1,2],[3,1]]x = 2queries = [3,4]return = [0,1]- Query 3 looks at
[1, 3]: every server gets a request, so the answer is 0. - Query 4 looks at
[2, 4]: servers 1 (time 2) and 2 (time 4) are busy, so only server 3 is idle.
Example 3
n = 5logs = [[4,100]]x = 10queries = [50]return = [5]- The only request is at time 100, outside
[40, 50], so all 5 servers are idle.
Constraints
1 <= n <= 1051 <= logs.length <= 2 × 1041 <= queries.length <= 2000logs[i].length == 21 <= logs[i][0] <= n1 <= logs[i][1] <= 1061 <= x <= 105x < queries[i] <= 106
More Salesforce Onsite Interview questions
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
- Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026
- Flatten Nested Map Paths with a StackONSITE INTERVIEW · Seen Sep 2026
- LFU CacheONSITE INTERVIEW · Seen Sep 2026
- Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Sliding-Window Frequency SnapshotsGoogle · ONSITE INTERVIEWGoogle interview questions
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Earliest Hour with Frequent Badge AccessIntuit · OAIntuit interview questions
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Top K Best-Selling Products in the Last N DaysAmazon · ONSITE INTERVIEW
- Message Event AggregationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions