FastPrepDocument Indexer Scheduling Metrics

Document Indexer Scheduling Metrics

Glean logoGlean● HardFULLTIMEPHONE SCREEN
Learn

Problem statement

You manage indexerCount document indexers numbered from 0 through indexerCount - 1. Document i arrives at time queueTimes[i] and occupies one indexer for processingTimes[i] time units.

Document i prefers indexer i % indexerCount. Starting there, scan indexers in increasing numeric order and wrap from the last indexer to indexer 0. Assign the document to the first indexer whose previous job finishes at or before its arrival time. If every indexer is busy, drop the document.

After all arrivals, rank every indexer by documents processed in descending order, breaking ties by smaller indexer number. Let topCount = min(k, indexerCount).

Return an integer array with this exact layout:

  1. the total number of successfully processed documents;
  2. the busiest indexer, using the ranking rule above;
  3. the number of successful documents processed by the first topCount ranked indexers;
  4. the total number of successfully processed documents again, as the denominator of the exact top-indexer share; and
  5. the topCount ranked indexer numbers.

The third and fourth values represent the exact share. For example, 3 and 4 mean 3/4 = 75%. When no document is processed, both share values are 0; indexer 0 is busiest by the tie rule.

Function

summarizeIndexerLoad(indexerCount: int, queueTimes: int[], processingTimes: int[], k: int) → int[]

Examples

Example 1

indexerCount = 3queueTimes = [1,2,3,7]processingTimes = [5,4,3,2]k = 2return = [4,0,3,4,0,1]

The four documents go to indexers 0, 1, 2, 0. Counts are [2,1,1], so indexer 0 is busiest and the deterministic top two are [0,1]. They processed 3/4 = 75% of all successful documents.

Example 2

indexerCount = 2queueTimes = [1,2,3,6]processingTimes = [5,5,1,1]k = 5return = [3,0,3,3,0,1]

The third document is dropped because both indexers are busy. At time 6, indexer 0 is free, so the last document wraps from preferred indexer 1 to indexer 0. Because k exceeds the indexer count, both indexers are returned.

Example 3

indexerCount = 3queueTimes = [1,2,3,4]processingTimes = [10,10,1,1]k = 2return = [4,2,3,4,2,0]

The fourth document prefers indexer 0, finds indexers 0 and 1 busy, and reaches indexer 2 after wrapping. Counts are [1,1,2], so the top two are [2,0] and their share is 3/4.

Constraints

  • 1 <= indexerCount <= 10^5.
  • 0 <= queueTimes.length = processingTimes.length <= 2 * 10^5.
  • 0 <= k <= 2 * 10^5.
  • 0 <= queueTimes[i] <= 10^9.
  • queueTimes is strictly increasing.
  • 1 <= processingTimes[i] <= 10^9.

More Glean problems

See Glean hiring insights
public int[] summarizeIndexerLoad(int indexerCount, int[] queueTimes, int[] processingTimes, int k) {
    // Write your code here.
}
indexerCount3
queueTimes[1,2,3,7]
processingTimes[5,4,3,2]
k2
expected[4,0,3,4,0,1]
Checking account…