Circular Worker Assignment and Top-K Load
Hard · Coding & Algorithms · Software Engineer · Technical Screen
Problem Statement
A document-ingestion cluster runs m parallel workers (indexers), numbered 0 through m - 1. Over time, n documents arrive in strictly increasing timestamp order (queue_time[0] < queue_time[1] < ... < queue_time[n - 1]). Each assigned document occupies a single worker exclusively for processing_time[i] time units.
Implement the scheduler simulation and workload summary:
def simulate_document_assignment(
m: int,
queue_time: List[int],
processing_time: List[int],
k: int,
) -> Dict[str, object]:
Each document i (0 <= i < n) is routed at arrival timestamp t = queue_time[i] using these rules:
- Preferred worker: Start probing at
base = i % m. - Availability: A worker is free at timestamp
tif it has not yet handled any document or its previous assignment finished at or beforet(finish_time <= t). - Circular fallback: Check
base; if busy, continue probing(base + 1) % m,(base + 2) % m, ...,(base + m - 1) % mand assign documentito the first free worker encountered. That worker becomes occupied untilt + processing_time[i]. - Drop on saturation: If all
mworkers are still busy at timestampt(finish_time > teverywhere), documentiis discarded immediately and never processed later.
Given k (1 <= k <= m), return a dictionary with four entries:
"total_processed": integer count of documents successfully assigned to a worker."most_processed_indexer": integer ID of the worker that handled the highest number of documents (if several workers tie for the maximum, any tied worker ID is valid; examples break ties by smallest worker ID)."top_indexers": list ofkdistinct worker IDs with the largest processed-document counts (any ordering or valid tie choice is permitted; examples sort by descending count and then ascending worker ID)."percentage": float (0.0to100.0) giving the share of allnarriving documents—dropped ones included— that were handled bytop_indexers(0.0whenn == 0).
Examples
Example 1
Input:
m = 2
queue_time = [1, 2, 4, 5]
processing_time = [8, 3, 2, 4]
k = 1
Output:
{
"total_processed": 3,
"most_processed_indexer": 1,
"top_indexers": [1],
"percentage": 50.0,
}
Explanation:
- Document 0 (t = 1, base = 0): worker 0 is free and stays busy until 1 + 8 = 9.
- Document 1 (t = 2, base = 1): worker 1 is free and stays busy until 2 + 3 = 5.
- Document 2 (t = 4, base = 0): worker 0 (until 9) and worker 1 (until 5) are both busy, so document 2 is dropped.
- Document 3 (t = 5, base = 1): worker 1 finishes at 5 <= 5 and takes document 3 until 5 + 4 = 9.
- Counts are [1, 2]: 3 documents succeeded, worker 1 leads with 2 documents, and top_indexers = [1] handled 2 out of all 4 arrivals (50.0%).
Example 2
Input:
m = 3
queue_time = [0, 1, 2, 4, 6]
processing_time = [3, 10, 10, 2, 5]
k = 2
Output:
{
"total_processed": 5,
"most_processed_indexer": 0,
"top_indexers": [0, 1],
"percentage": 80.0,
}
Explanation:
- Documents 0, 1, and 2 land on workers 0, 1, and 2, finishing at times 3, 11, and 12.
- Document 3 (t = 4, base = 0) reuses worker 0 (3 <= 4), occupying it until 6.
- Document 4 (t = 6, base = 1) finds workers 1 (11 > 6) and 2 (12 > 6) busy, wraps around to worker 0 (6 <= 6), and occupies it until 11.
- Counts are [3, 1, 1]: worker 0 handled 3 documents, workers 1 and 2 tie at 1 each ([0, 1] or [0, 2] are both valid), and 4 / 5 = 80.0%.
Constraints
1 <= m <= 100,0000 <= n == len(queue_time) == len(processing_time) <= 100,000queue_timeis strictly increasing (queue_time[i] < queue_time[i + 1]).processing_time[i] >= 11 <= k <= m
Step-by-step walkthrough
Restate the rules and output dictionary
We have
mparallel indexers numbered0tom - 1, andndocuments arriving at strictly increasing timesqueue_time[0] < queue_time[1] < ... < queue_time[n - 1].When document
iarrives atarrival_time = queue_time[i]:- Its preferred indexer is
base = i % m. - An indexer is available if it has never run a job or its current job finishes at or before
arrival_time(free_time <= arrival_time). - We check indexers in cyclic order
base, base + 1, ..., m - 1, 0, ..., base - 1and assign the document to the first available indexer, making it busy untilarrival_time + processing_time[i]. - If no indexer is available at
arrival_time, the document is dropped.
The judge expects a dictionary with four exact keys:
Key Value "total_processed"Number of documents assigned (not dropped) "most_processed_indexer"Indexer ID with the highest processed count "top_indexers"List of kindexer IDs with the highest counts"percentage"100.0 * (sum of top_k counts) / n(or0.0ifn == 0)Two subtle details to lock down up front:
- Tie-breaking and type for
"top_indexers": Although any valid tie-break among equal-count workers is allowed, callers compare"top_indexers"as alistofkdistinct worker IDs. Sorting by(-counts[j], j)(most documents first, smaller indexer ID on ties) produces a clean, deterministic list such as[0, 1]in Example 2. - Denominator of
"percentage": We measure the topkworkers' share out of every arriving document (dropped ones included), dividing byn = len(queue_time)rather thantotal_processed.
- Its preferred indexer is
Brute force and why scanning is O(n * m)
A direct simulation keeps
free_time[j]for each indexerjand scansstep = 0, 1, ..., m - 1around the circle(base + step) % muntil it findsfree_time[j] <= arrival_time.That scan is simple and serves as the reference oracle in the tests, but whenever almost all indexers are busy, one document inspects up to
mindexers. Acrossndocuments, that takesO(n * m)time. To bring each document down toO(log m), we need a data structure that answers: "Who is the leftmost indexer at or afterstart_idwhosefree_time <= arrival_time?" without touching busy ranges.Key idea: a tournament tree (segment tree) of free times
Think of organizing the
mindexers into a binary tournament bracket (called a min-segment tree). Each leaf stores one indexer'sfree_time, and each parent box stores the minimum (earliest)free_timeamong its two children:Example for m = 3 (padded to leaf_capacity = 4): [node 1: min(0..3) = -inf] / \ [node 2: min(0..1) = 3] [node 3: min(2..3) = -inf] / \ / \ [leaf 4] [leaf 5] [leaf 6] [leaf 7] idx 0: 3 idx 1: 11 idx 2: -inf pad 3: +infWhy this bracket makes queries fast:
- If a parent box says
min = 3and a document arrives atarrival_time = 2, then nobody in that entire group is free by time2(3 > 2). We skip the whole group inO(1)time! - Conversely, if a parent box has
min <= arrival_time, at least one indexer inside that group is free. Checking the left child before the right child walks straight down to the smallest free indexer ID! - Unused padding leaves (
idx >= m) holdMISSING = +inf, so they never beat a real timestamp and can never be chosen. Real indexers start atFREE = -inf, meaning free at any arrival time.
- If a parent box says
Build the tree and update one indexer
We pad
mup toleaf_capacity(the smallest power of two>= m) and store the whole bracket in a flat listself.treeof length2 * leaf_capacity, wherenode = 1is the root andnode's children sit at2 * nodeand2 * node + 1.When an indexer gets a new job finishing at
free_time, only its leaf and theO(log m)ancestors directly above it can change:FREE = float("-inf") MISSING = float("inf") class FreeTimeTree: """Min-segment tree over m indexers. Leaf (leaf_capacity + j) holds the timestamp when indexer j next becomes free; every internal node holds min(left_child, right_child) over its leaf range. """ def __init__(self, m: int): # Round m up to a power of two so leaves sit cleanly at indices [leaf_capacity, 2 * leaf_capacity). self.leaf_capacity = 1 while self.leaf_capacity < m: self.leaf_capacity *= 2 # tree[1] is the root; tree[2 * node] and tree[2 * node + 1] are node's children. self.tree = [MISSING] * (2 * self.leaf_capacity) for indexer_id in range(m): self.tree[self.leaf_capacity + indexer_id] = FREE # Build internal minimums bottom-up from the leaves. for node in range(self.leaf_capacity - 1, 0, -1): left_min = self.tree[2 * node] right_min = self.tree[2 * node + 1] self.tree[node] = min(left_min, right_min) def update_free_time(self, indexer_id: int, free_time: float) -> None: """Set indexer_id's next free timestamp and refresh ancestor minimums along the root path.""" node = self.leaf_capacity + indexer_id self.tree[node] = free_time node //= 2 while node >= 1: left_min = self.tree[2 * node] right_min = self.tree[2 * node + 1] self.tree[node] = min(left_min, right_min) node //= 2Search for the first free indexer at or after `start_id`
_search(node, node_lo, node_hi, start_id, arrival_time)looks inside the leaf range[node_lo, node_hi]covered bynode:- Prune: If
node_hi < start_id(the whole range lies left ofstart_id) orself.tree[node] > arrival_time(every indexer in this range finishes strictly afterarrival_time), return-1immediately. - Base case: If
node_lo == node_hi, we reached a single leaf that is>= start_idand hasfree_time <= arrival_time— returnnode_lo. - Recurse left, then right: Try the left child
[node_lo, mid]first; only if it returns-1do we try the right child[mid + 1, node_hi].
def first_available(self, start_id: int, arrival_time: int) -> int: """Return the smallest indexer ID >= start_id with free_time <= arrival_time, or -1 if none.""" return self._search(1, 0, self.leaf_capacity - 1, start_id, arrival_time) def _search( self, node: int, node_lo: int, node_hi: int, start_id: int, arrival_time: int, ) -> int: # Prune if this subtree lies completely before start_id, or if even its earliest # indexer finishes strictly after arrival_time (note: == arrival_time IS available). if node_hi < start_id or self.tree[node] > arrival_time: return -1 # Reaching a leaf that passed the checks above means this leaf is the leftmost match. if node_lo == node_hi: return node_lo mid = (node_lo + node_hi) // 2 left_child = 2 * node right_child = 2 * node + 1 # Always try the left half first so we pick the smallest available indexer ID. found_id = self._search(left_child, node_lo, mid, start_id, arrival_time) if found_id == -1: found_id = self._search(right_child, mid + 1, node_hi, start_id, arrival_time) return found_idWhy does
_searchrun inO(log m)time even though it has two recursive calls? At most one node per level straddlesstart_id; every other node we enter lies completely at or afterstart_id, and the first such node whose minimum is<= arrival_timeis guaranteed to contain the answer, so the recursion descends straight down to one leaf and stops!- Prune: If
Handle circular wrap-around in two queries
The cyclic probe order starting from
baseis simply two left-to-right segments:Indexers: 0 1 ... base-1 | base base+1 ... m-1 |<--- Pass 2 ------->| |<------ Pass 1 ------>|- Pass 1: Call
tree.first_available(base, arrival_time)to check[base, m - 1]. - Pass 2: If Pass 1 returns
-1, nobody in[base, m - 1]is free, so callingtree.first_available(0, arrival_time)can only find an indexer in[0, base - 1](or return-1if allmindexers are busy).
def pick_indexer(tree: FreeTimeTree, base: int, arrival_time: int) -> int: """Find the first free indexer in cyclic order: base, base+1, ..., m-1, 0, ..., base-1.""" # Pass 1: check indexers from base up to m - 1. chosen_id = tree.first_available(base, arrival_time) if chosen_id == -1: # Pass 2: nobody in [base, m - 1] is free, so wrap around and check from 0. chosen_id = tree.first_available(0, arrival_time) return chosen_id- Pass 1: Call
Run the simulation, rank indexers, and trace Example 2
Now we step through
i = 0 .. n - 1, update the chosen indexer'sfree_timeandcounts, then sort(-counts[j], j)to extractmost_processed_indexer,top_indexers, andpercentage.Let's trace Example 2 (
m = 3,queue_time = [0, 1, 2, 4, 6],processing_time = [3, 10, 10, 2, 5],k = 2):Initial leaves (idx 0, 1, 2, pad 3): [-inf, -inf, -inf, +inf], root min = -inf i = 0, t = 0, p = 3, base = 0 % 3 = 0: Pass 1 from 0 -> idx 0 (-inf <= 0). Update idx 0 to 0 + 3 = 3. leaves = [3, -inf, -inf, +inf], counts = [1, 0, 0] i = 1, t = 1, p = 10, base = 1 % 3 = 1: Pass 1 from 1 -> idx 1 (-inf <= 1). Update idx 1 to 1 + 10 = 11. leaves = [3, 11, -inf, +inf], counts = [1, 1, 0] i = 2, t = 2, p = 10, base = 2 % 3 = 2: Pass 1 from 2 -> idx 2 (-inf <= 2). Update idx 2 to 2 + 10 = 12. leaves = [3, 11, 12, +inf], counts = [1, 1, 1] i = 3, t = 4, p = 2, base = 3 % 3 = 0: Pass 1 from 0 -> idx 0 (3 <= 4). Update idx 0 to 4 + 2 = 6. leaves = [6, 11, 12, +inf], counts = [2, 1, 1] i = 4, t = 6, p = 5, base = 4 % 3 = 1: Pass 1 from 1 -> -1 (11 > 6 and 12 > 6). Pass 2 from 0 -> idx 0 (6 <= 6). Update idx 0 to 6 + 5 = 11. leaves = [11, 11, 12, +inf], counts = [3, 1, 1]Sorting
(-counts[j], j)gives[(-3, 0), (-1, 1), (-1, 2)]:total_processed = 5most_processed_indexer = 0top_indexers = [0, 1]percentage = 100.0 * (3 + 1) / 5 = 80.0
Complete solution
from typing import Any, Dict, List, Optional, Set, Tuple # FREE (-inf) means an indexer has no active job and is available at any arrival time. # MISSING (+inf) fills unused power-of-two leaf slots so they are never chosen. FREE = float("-inf") MISSING = float("inf") class FreeTimeTree: """Min-segment tree over m indexers. Leaf (leaf_capacity + j) holds the timestamp when indexer j next becomes free; every internal node holds min(left_child, right_child) over its leaf range. """ def __init__(self, m: int): # Round m up to a power of two so leaves sit cleanly at indices [leaf_capacity, 2 * leaf_capacity). self.leaf_capacity = 1 while self.leaf_capacity < m: self.leaf_capacity *= 2 # tree[1] is the root; tree[2 * node] and tree[2 * node + 1] are node's children. self.tree = [MISSING] * (2 * self.leaf_capacity) for indexer_id in range(m): self.tree[self.leaf_capacity + indexer_id] = FREE # Build internal minimums bottom-up from the leaves. for node in range(self.leaf_capacity - 1, 0, -1): left_min = self.tree[2 * node] right_min = self.tree[2 * node + 1] self.tree[node] = min(left_min, right_min) def update_free_time(self, indexer_id: int, free_time: float) -> None: """Set indexer_id's next free timestamp and refresh ancestor minimums along the root path.""" node = self.leaf_capacity + indexer_id self.tree[node] = free_time node //= 2 while node >= 1: left_min = self.tree[2 * node] right_min = self.tree[2 * node + 1] self.tree[node] = min(left_min, right_min) node //= 2 def first_available(self, start_id: int, arrival_time: int) -> int: """Return the smallest indexer ID >= start_id with free_time <= arrival_time, or -1 if none.""" return self._search(1, 0, self.leaf_capacity - 1, start_id, arrival_time) def _search( self, node: int, node_lo: int, node_hi: int, start_id: int, arrival_time: int, ) -> int: # Prune if this subtree lies completely before start_id, or if even its earliest # indexer finishes strictly after arrival_time (note: == arrival_time IS available). if node_hi < start_id or self.tree[node] > arrival_time: return -1 # Reaching a leaf that passed the checks above means this leaf is the leftmost match. if node_lo == node_hi: return node_lo mid = (node_lo + node_hi) // 2 left_child = 2 * node right_child = 2 * node + 1 # Always try the left half first so we pick the smallest available indexer ID. found_id = self._search(left_child, node_lo, mid, start_id, arrival_time) if found_id == -1: found_id = self._search(right_child, mid + 1, node_hi, start_id, arrival_time) return found_id def pick_indexer(tree: FreeTimeTree, base: int, arrival_time: int) -> int: """Find the first free indexer in cyclic order: base, base+1, ..., m-1, 0, ..., base-1.""" # Pass 1: check indexers from base up to m - 1. chosen_id = tree.first_available(base, arrival_time) if chosen_id == -1: # Pass 2: nobody in [base, m - 1] is free, so wrap around and check from 0. chosen_id = tree.first_available(0, arrival_time) return chosen_id def simulate_document_assignment( m: int, queue_time: List[int], processing_time: List[int], k: int, ) -> Dict[str, object]: n = len(queue_time) tree = FreeTimeTree(m) # counts[j]: number of documents successfully assigned to indexer j. counts = [0] * m total_processed = 0 # Phase 1: simulate each arriving document in chronological order. for i in range(n): arrival_time = queue_time[i] base = i % m chosen_id = pick_indexer(tree, base, arrival_time) if chosen_id == -1: # All m indexers are busy at arrival_time; drop this document. continue finish_time = arrival_time + processing_time[i] tree.update_free_time(chosen_id, finish_time) counts[chosen_id] += 1 total_processed += 1 # Phase 2: rank all m indexers by (-processed_count, indexer_id) so higher counts come # first and ties consistently go to smaller indexer IDs (e.g. [0, 1] when 1 and 2 tie). ranked_pairs = [] for indexer_id in range(m): ranked_pairs.append((-counts[indexer_id], indexer_id)) ranked_pairs.sort() ranked_ids = [] for neg_count, indexer_id in ranked_pairs: ranked_ids.append(indexer_id) top_indexers = ranked_ids[:k] # Phase 3: compute percentage out of ALL n queued documents (dropped ones included). top_total = 0 for indexer_id in top_indexers: top_total += counts[indexer_id] percentage = (100.0 * top_total / n) if n > 0 else 0.0 return { "total_processed": total_processed, "most_processed_indexer": ranked_ids[0], "top_indexers": top_indexers, "percentage": percentage, }✅ Submit now — all tests should pass.
Intuition & how it works
Imagine m checkout clerks standing in a row, each holding a sign showing the timestamp when their current customer will finish. Document i wants to check clerks starting at base = i % m, moving right to m - 1, and wrapping back to 0 .. base - 1 until it spots a sign <= arrival_time. Instead of walking past thousands of busy clerks one by one, imagine grouping clerks in pairs, pairs of pairs, and so on like a sports tournament bracket, where each manager above a group holds a sign showing the earliest finish time in that group. When a document arrives at arrival_time, any group whose manager's sign is strictly greater than arrival_time has zero free clerks and can be skipped in a single glance, while a group with min <= arrival_time lets us step straight down to its leftmost free clerk!
A naive loop checks (base + step) % m for step = 0, 1, ..., m - 1 on every document. Whenever almost all m indexers are busy, each document checks nearly all m indexers before wrapping to a free one or getting dropped. Across n documents, that linear scan takes O(n * m) time, which bogs down when n and m are large.
Using a segment tree (a binary tree over an array where each internal node stores an aggregate—here the minimum value—of its child range) turns both circular lookups and single-indexer finish-time updates into O(log m) tree walks. Let's trace Example 1 (m = 2, k = 1, queue_time = [1, 2, 4, 5], processing_time = [8, 3, 2, 4]):
- Start with leaf free times
[-inf, -inf]andcounts = [0, 0]. - Doc
0(t = 1,base = 0): picks indexer0, sets leaf0to1 + 8 = 9. Leaves:[9, -inf],counts = [1, 0]. - Doc
1(t = 2,base = 1): picks indexer1, sets leaf1to2 + 3 = 5. Leaves:[9, 5],counts = [1, 1]. - Doc
2(t = 4,base = 0): root minimummin(9, 5) = 5 > 4, so both Pass 1 and Pass 2 prune immediately and drop Doc2! - Doc
3(t = 5,base = 1): leaf1hasfree_time = 5 <= 5, so indexer1takes Doc3until9(counts = [1, 2]), givingtotal_processed = 3,top_indexers = [1], andpercentage = 100.0 * 2 / 4 = 50.0(the dropped arrival still counts in denominatorn = 4).
Complexity
- Time:
O((m + n) log m). Building the segment tree initializes an array of at most4 * mentries inO(m)time. Each of thenarriving documents runs at most twofirst_availabletree searches (O(log m)each, visiting at most a constant number of nodes per tree level) and at most oneupdate_free_timepoint update (an update to a single leaf and itsO(log m)ancestors up to the root). Ranking themindexers at the end sortsmtuples inO(m log m)time. - Space:
O(m). Roundingmup toleaf_capacity < 2 * mcreates atreearray of2 * leaf_capacity < 4 * mnumbers, andcountsplusranked_pairseach storementries.
Edge cases
- Job completes at the exact arrival time (
free_time == arrival_time): Availability requires completion no later thanarrival_time, so_searchonly prunes whenself.tree[node] > arrival_time, treating==as free. - All indexers busy (dropped documents): Both Pass 1 (
start_id = base) and Pass 2 (start_id = 0) return-1. The document is dropped (total_processeddoes not increment), yetnin100.0 * top_total / nstill includes it. - Empty document list (
n = 0): Guardingif n > 0 else 0.0avoids aZeroDivisionErrorand returns0.0withtotal_processed = 0. mis not a power of two: Extra leavesm .. leaf_capacity - 1stay initialized toMISSING = +inf, which is greater than every finitearrival_timeand can never be selected.- First arrival at
t = 0(or even negativet): Initializing real leaves toFREE = -infensures every indexer is available before its first job, regardless of how smallqueue_time[0]is. k = m:top_indexersincludes allmindexers, sotop_total == total_processedandpercentage == 100.0 * total_processed / n.
Common mistakes
- Dividing
percentagebytotal_processedinstead ofn: The specification measures top-kthroughput as a share of every arriving document—dropped ones included—so the denominator must belen(queue_time). - Returning
top_indexersas a Pythonset: Callers inspectgot['top_indexers']as an indexable list/tuple sequence (such as[1]or[0, 1]), and_samecompares lists/tuples rather than sets. Returning a deterministically sorted list ((-counts[j], j)) passes both exact and tie-tolerant checks. - Searching from indexer
0instead ofbase = i % m: Ifbase = 1is busy while both0and2are free, cyclic order must choose2before wrapping around to0. - Using a single min-heap keyed only by
finish_timeto pick indexers: That picks whichever indexer finished earliest in time, ignoring the circulari % mpreference rule completely. - Forgetting Pass 2 (wrap-around): Checking only
[base, m - 1]misses free indexers in[0, base - 1].
Alternative approaches
- Two min-heaps with unrolled circular slots (
O((n + m) log m)time,O(m)space): Keep busy indexers in a(finish_time, j)min-heap and free indexers in a min-heap keyed byi + (j - i) % m(their next position in[i, i + m)on an unrolled number line). Becausequeue_timeincreases monotonically, waking finished indexers before each arrival and popping the minimum slot achieves the sameO((n + m) log m)complexity with slightly less boilerplate, though the segment tree is easier to reason about without modular heap invariants. - Partial selection with
heapq.nsmallest(k, ranked_pairs)(O(m log k)ranking): Replaces the finalO(m log m)sort withO(m + k log m)orO(m log k), thoughO(m log m)is already dominated by or equal to the tree build + simulation whenn >= m.
Follow-up questions
- Does the segment-tree scheduler still work if multiple documents can arrive at the exact same timestamp? As long as simultaneous arrivals are routed in array index order
iandprocessing_time[i] > 0, the exact sameFreeTimeTreelogic works unchanged: assigning a worker at timestamptupdates its leaf tot + processing_time[i] > t, so later arrivals at the same timestamptskip it automatically. (If zero-duration jobsprocessing_time[i] == 0were also permitted, a worker could finish instantaneously attand accept another arrival att.) - How would you change the design if arriving documents wait in a FIFO buffer instead of being dropped when all workers are busy? Add a FIFO queue (a First-In, First-Out buffer serving the earliest waiting arrival next) alongside a min-heap of
(finish_time, indexer_id)completion events. Before routing a new arrival at timestampt, pop every completion event withfinish_time <= tin chronological order and immediately hand that freed worker the head of the waiting queue starting atfinish_time; only when the waiting queue is empty does the new arrival probe circularly fromi % m. - How could you report the top-k workers and their share on the fly after every arrival without re-sorting all m workers? Maintain
(-counts[j], j)inside a balanced binary search tree (an ordered set supportingO(log m)insert, delete, and rank lookups) together with the running sumtop_totalof its smallestktuples. Each assignment incrementscounts[chosen_id]by1, repositions that single worker in the tree, and updatestop_totalinO(log m)time rather thanO(m log m).
Follow-up questions
- Does the segment-tree scheduler still work if multiple documents can arrive at the exact same timestamp?
- How would you change the design if arriving documents wait in a FIFO buffer instead of being dropped when all workers are busy?
- How could you report the top-k workers and their share on the fly after every arrival without re-sorting all m workers?
Similar questions
- Station Reachability Across Time-Indexed Train Schedules
- Minimum Removals for Valid Parenthesis Nesting
- Station Reachability Across Timed Rail Routes
- Earliest Train Arrival and Itinerary
- Logarithmic Selection of the k-th Largest Element
- Kth Largest Element Across Two Sorted Lists
More Glean interview questions
- Daily Active Users and 30-Day Rolling MAU Easy
- Zero-Padded DAU, Rolling MAU, and Identity Rehash Inflation Medium
- Alphabet-First Wikipedia Crawler with Rate Pacing Medium Pro
- Score-Sorted React Feed with Vote Toggles and Pins Medium Pro
- Station Reachability Across Time-Indexed Train Schedules Medium Pro
- Minimum Removals for Valid Parenthesis Nesting Medium Pro
- Enterprise Colleague Proximity and Similarity Service Medium Pro
- Multi-Source Real-Time Autocomplete for Workplace Search Medium Pro
- Testing Strategy for a Large-Scale Leaf Counter Medium Pro
- Modeling Pairwise Collaboration Distance Across an Enterprise Medium Pro