PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Simulate a round-robin dispatcher over m servers with capacities and down flags. Return the highest-index server among those that handled the maximum number of packages, or -1 if none handled any.

Constraints

  • Package scan wraps around
  • Pointer changes only after a successful assignment

Examples

Input: (3, [5, 5, 5], [False, False, False], [2, 2, 2, 2])

Expected Output: 0

Input: (3, [1, 10, 10], [False, True, False], [2, 2, 20])

Expected Output: 2

Input: (2, [1, 1], [True, True], [1])

Expected Output: -1

Hints

  1. For each package, scan at most m servers from the pointer.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding 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)