FastPrepCount Zero Request Servers
Problems/Count Zero Request Servers

Count Zero Request Servers

Salesforce logoSalesforce● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Salesforce asked this as the second question in the same onsite coding round. The candidate said it was similar to a well-known public problem, which they named with a number. They ran out of time, only explained an approach aloud, and found it hard. The report gives no other detail.

So our version follows that well-known public problem. Given server request logs, a window length x and query times, count for each query the servers with no request in [query - x, query]. We do not know which variant the round actually used, so this is the public version as is. We use fewer logs and queries than the public limits (up to 2 x 10^4 logs and 2000 queries) to keep the test output small. The other limits are the public ones.

Our version is about 70% the same as the reported question.

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 <= 105
  • 1 <= logs.length <= 2 × 104
  • 1 <= queries.length <= 2000
  • logs[i].length == 2
  • 1 <= logs[i][0] <= n
  • 1 <= logs[i][1] <= 106
  • 1 <= x <= 105
  • x < 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

Interview reports that mention this question

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience

Salesforce interview experiences

  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int[] countServers(int n, int[][] logs, int x, int[] queries) {
        // Write your code here.
    }
}
Checking account…