PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Capital One

Simulate round-robin package assignment to servers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates array-based simulation and control-flow skills for load distribution, including pointer management, modular wrap-around scanning, capacity checks, and handling disabled servers.

  • medium
  • Capital One
  • Coding & Algorithms
  • Machine Learning Engineer

Simulate round-robin package assignment to servers

Company: Capital One

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are simulating a round-robin dispatcher across **m servers** labeled `0..m-1`. - Each server `i` has an initial remaining capacity `cap[i]` (a non-negative integer). - Some servers are **shut down** and must be skipped; this is given as a boolean array `down[i]`. - A sequence of **n packages** arrives in order; package `k` has size `pkg[k]` (a positive integer). Dispatch rule (round-robin with skipping and wrap-around): 1. Maintain a pointer `p` that indicates where scanning starts. Initially `p = 0`. 2. For each arriving package `k`, starting from server `p`, scan servers `p, p+1, ..., m-1, 0, 1, ...` (wrapping around) to find the **first** server `j` such that: - `down[j] == false`, and - `cap[j] >= pkg[k]`. 3. If such a server `j` exists, assign the package to `j`, decrement `cap[j] -= pkg[k]`, and increment `handled[j]` by 1. Then set `p = (j + 1) mod m` for the next package. 4. If **no** server can take the package, the package is dropped and `p` does not change. Return the **highest-index** server that handled the **maximum** number of packages. If all servers handled 0 packages, return `-1`. **Input:** `m`, arrays `cap[0..m-1]`, `down[0..m-1]`, and `pkg[0..n-1]`. **Output:** an integer server index. Include typical edge cases in your reasoning (wrap-around behavior, all servers down, large package sizes, ties).

Quick Answer: This question evaluates array-based simulation and control-flow skills for load distribution, including pointer management, modular wrap-around scanning, capacity checks, and handling disabled servers.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
Capital One logo
Capital One
Jan 20, 2026, 12:00 AM
Machine Learning Engineer
Take-home Project
Coding & Algorithms
4
0
Loading...

You are simulating a round-robin dispatcher across m servers labeled 0..m-1.

  • Each server i has an initial remaining capacity cap[i] (a non-negative integer).
  • Some servers are shut down and must be skipped; this is given as a boolean array down[i] .
  • A sequence of n packages arrives in order; package k has size pkg[k] (a positive integer).

Dispatch rule (round-robin with skipping and wrap-around):

  1. Maintain a pointer p that indicates where scanning starts. Initially p = 0 .
  2. For each arriving package k , starting from server p , scan servers p, p+1, ..., m-1, 0, 1, ... (wrapping around) to find the first server j such that:
    • down[j] == false , and
    • cap[j] >= pkg[k] .
  3. If such a server j exists, assign the package to j , decrement cap[j] -= pkg[k] , and increment handled[j] by 1. Then set p = (j + 1) mod m for the next package.
  4. If no server can take the package, the package is dropped and p does not change.

Return the highest-index server that handled the maximum number of packages. If all servers handled 0 packages, return -1.

Input: m, arrays cap[0..m-1], down[0..m-1], and pkg[0..n-1].

Output: an integer server index.

Include typical edge cases in your reasoning (wrap-around behavior, all servers down, large package sizes, ties).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Machine Learning Engineer•Capital One Machine Learning Engineer•Capital One Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.