Automation

Hosts low on disk

Evaluate normalized disk usage without dividing by an unknown capacity.

In production

Disk pressure alerts prevent full volumes. Division rounding can hide a disk that is already over the threshold.

What it must return

Return disks whose used/capacity ratio meets the threshold, using a comparison that avoids float rounding traps.

  • Each disk has name, used and capacity (nonnegative integers). threshold_percent is 0–100. Include disks with positive capacity and used/capacity*100 >= threshold. Preserve input order. Zero capacity is unknown and excluded.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Guard capacity before comparing utilization.
  • Cross multiplication avoids division error.
  • Do not mutate the input.

Signature

pressured_disks(disks, threshold_percent)

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

At threshold

disks

[
  {
    "name": "a",
    "used": 80,
    "capacity": 100
  },
  {
    "name": "b",
    "used": 79,
    "capacity": 100
  }
]

threshold_percent

80

Expected

[
  "a"
]

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 8 in Automation passed in Python on this device.

Next: Secrets in a structured log