Document Indexer Scheduling Metrics
Updated
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 these values, in this order:
- the total number of successfully processed documents;
- the busiest indexer, using the ranking rule above;
- the number of successful documents processed by the first
topCountranked indexers; - the total number of successfully processed documents again, as the denominator of the exact top-indexer share; and
- the
topCountranked 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 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.queueTimesis strictly increasing.1 <= processingTimes[i] <= 10^9.
More Glean Phone Screen questions
Similar questions at other companies
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN
- Finish Time of Fixed-Length CPU TasksGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
- Allocate Orders with FIFO and Pro RataAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Progressive Banking SystemAirbnb · OAAirbnb interview questions
- Cloud Compute Credits SystemCoinbase · OACoinbase interview questions
- Initial Public OfferingPoint72 · OAPoint72 interview questions
- Inventory AllocationAmazon · OA
- Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions