InterviewDB
Experience
Engine Utilization: Compute and Report Resource Utilization Across Processing Engines
phone
Interview Experience
Round 1 Coding
Problem
You have a pool of processing engines. Each engine receives tasks over time. Given a log of (engine_id, task_id, start_time, end_time), compute each engine's utilization percentage over a specified observation window, and identify idle periods longer than a threshold.
python
def engine_utilization(
logs: list[tuple[str, str, int, int]],
window_start: int,
window_end: int
) -> dict[str, float]:
**returns** {engine_id: utilization_percent} for the window
...
def find_idle_periods(
logs: list[tuple[str, str, int, int]],
engine_id: str,
min_idle: int
) -> list[tuple[int, int]]:
**returns** list of (start, end) idle intervals >= min_idle
...
Example
logs = [
("E1", "T1", 0, 30),
("E1", "T2", 50, 80),
("E2", "T3", 10, 90),
]
engine_utilization(logs, 0, 100)
# E1: 30+30=60 busy out of 100 -> 60.0%
# E2: 80 busy out of 100 -> 80.0%
# -> {"E1": 60.0, "E2": 80.0}
find_idle_periods(logs, "E1", min_idle=15)
# -> [(30,50)] gap of 20 units >= 15
Follow-ups
- What if task intervals overlap for the same engine — how do you merge them before computing utilization?
- How would you detect which engine is the bottleneck (highest utilization) in a pipeline?
- How would you visualize utilization as a Gantt chart in ASCII output?
- How does your solution scale when logs contain millions of records?
Full Details
Round 1 Coding
Problem
You have a pool of processing engines. Each engine receives tasks over time. Given a log of (engine_id, task_id, start_time, end_time), compute each engine's utilization percentage over a specified observation window, and identify idle periods longer than a threshold.
python
def engine_utilization(
logs: list[tuple[str, str, int, int]],
window_start: int,
window_end: int
) -> dict[str, float]:
**returns** {engine_id: utilization_percent} for the window
...
def find_idle_periods(
logs: list[tuple[str, str, int, int]],
engine_id: str,
min_idle: int
) -> list[tuple[int, int]]:
**returns** list of (start, end) idle intervals >= min_idle
...
Example
logs = [
("E1", "T1", 0, 30),
("E1", "T2", 50, 80),
("E2", "T3", 10, 90),
]
engine_utilization(logs, 0, 100)
# E1: 30+30=60 busy out of 100 -> 60.0%
# E2: 80 busy out of 100 -> 80.0%
# -> {"E1": 60.0, "E2": 80.0}
find_idle_periods(logs, "E1", min_idle=15)
# -> [(30,50)] gap of 20 units >= 15
Follow-ups
- What if task intervals overlap for the same engine — how do you merge them before computing utilization?
- How would you detect which engine is the bottleneck (highest utilization) in a pipeline?
- How would you visualize utilization as a Gantt chart in ASCII output?
- How does your solution scale when logs contain millions of records?
Free preview. Unlock all Samsara questions →
About This Question
This is a candidate experience report from a samsara interview during the phone round.
More Samsara Interview Questions
InterviewDB
Samsara SWE Phone - Axis Permutation
InterviewDB
Command Parser: Parse and Dispatch Shell-Like Commands from User Input
InterviewDB
Samsara SWE Phone - Concurrent Meetings
InterviewDB
Engine States: Model a Vehicle Engine Using a Finite State Machine
InterviewDB
Samsara SWE Onsite - Intervals Merging