Simulate bus boarding with priority and wheelchairs

Quick Overview

This question evaluates queue and priority handling, stable ordering, capacity accounting, constraint handling for wheelchair riders, and the ability to design unit tests and articulate trade-offs within the Software Engineering Fundamentals category.

Simulate bus boarding with priority and wheelchairs

Company: Instacart

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

You are implementing a simplified bus boarding simulator. Model: - `Person` has at least: - `id` (string/int) - `priority` (boolean): if true, they should board before non-priority riders. - `wheelchair` (optional): if present, the person uses a wheelchair. - `capacityCost` (int): how many capacity units they consume when boarding (defaults to 1 for a normal rider; wheelchair riders may have different costs). - `Bus` has: - `totalCapacity` (int) - `maxWheelchairs = 2` Task A — Priority boarding: - Given a waiting line of people (in arrival order) and a bus with remaining capacity, board as many people as possible. - Priority riders should be boarded before non-priority riders. - Preserve relative order within the priority group and within the non-priority group (stable ordering). - Return (1) the list of boarded riders in the order they boarded and (2) the remaining waiting line. Task B — Explain tradeoffs: - Explain why you implemented it that way. - Provide at least one alternative approach and compare time/space complexity and maintainability. - Mention what you would change for “real production” (e.g., extensibility, fairness/starvation, configurability). Task C — Unit tests: - Write unit tests for Task A (and for Task D below if time). Specify key edge cases. Task D — Add wheelchair constraints: - Extend boarding logic with these rules: - A bus can carry at most 2 wheelchair riders. - Each wheelchair rider consumes `capacityCost` units (not necessarily 1). - Non-wheelchair riders consume 1 unit. - Continue to respect priority boarding and stable ordering within groups. You may define your own function signatures (e.g., `board(bus, waitingQueue)`).

Quick Answer: This question evaluates queue and priority handling, stable ordering, capacity accounting, constraint handling for wheelchair riders, and the ability to design unit tests and articulate trade-offs within the Software Engineering Fundamentals category.

|Home/Software Engineering Fundamentals/Instacart
Instacart logo
Instacart
Mar 4, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
26
0

You are implementing a simplified bus boarding simulator.

Model:

  • Person has at least:
    • id (string/int)
    • priority (boolean): if true, they should board before non-priority riders.
    • wheelchair (optional): if present, the person uses a wheelchair.
    • capacityCost (int): how many capacity units they consume when boarding (defaults to 1 for a normal rider; wheelchair riders may have different costs).
  • Bus has:
    • totalCapacity (int)
    • maxWheelchairs = 2

Task A — Priority boarding:

  • Given a waiting line of people (in arrival order) and a bus with remaining capacity, board as many people as possible.
  • Priority riders should be boarded before non-priority riders.
  • Preserve relative order within the priority group and within the non-priority group (stable ordering).
  • Return (1) the list of boarded riders in the order they boarded and (2) the remaining waiting line.

Task B — Explain tradeoffs:

  • Explain why you implemented it that way.
  • Provide at least one alternative approach and compare time/space complexity and maintainability.
  • Mention what you would change for “real production” (e.g., extensibility, fairness/starvation, configurability).

Task C — Unit tests:

  • Write unit tests for Task A (and for Task D below if time). Specify key edge cases.

Task D — Add wheelchair constraints:

  • Extend boarding logic with these rules:
    • A bus can carry at most 2 wheelchair riders.
    • Each wheelchair rider consumes capacityCost units (not necessarily 1).
    • Non-wheelchair riders consume 1 unit.
  • Continue to respect priority boarding and stable ordering within groups.

You may define your own function signatures (e.g., board(bus, waitingQueue)).

Loading comments...