Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Weighted round-robin task scheduler

Python data engineering interview problem. Difficulty: advanced. Pattern: Streaming. About 20 minutes. Part of the Pro drill bank.

A task scheduler should pick workers in weighted round-robin so a worker with twice the weight gets roughly twice the jobs.

Simulate weighted round-robin assignment for a number of steps.

Requirements

  • Higher weight means more frequent picks.
  • The sequence length equals steps.

Constraints

  • workers: names with weights.
  • steps: how many assignments to emit.
  • A weight of 0 should never be picked.
  • One worker takes every step if it is the only positive weight.

Examples

Input: weighted_round_robin([('a', 2), ('b', 1)], 5) Output: ['a', 'a', 'b', 'a', 'a'] This input follows the stated rules and produces this output.

Topics: lakebench, python, queue.

More Python interview questions · All interview problems · Learn data engineering

advanced

Weighted round-robin task scheduler

Interview-style drill: Simulate a scheduler that cycles through workers, giving each a number of turns proportional to its weight.

Simulate weighted round-robin assignment for a number of steps.