PracticeArrays

Count Readings At or Above the Alert Floor

BeginnerArraystraversalaccumulationcomparison Time not estimated Not started

Context

A monitoring service receives a batch of integer telemetry readings from a device. An alert floor identifies readings that are high enough to qualify for review. Repeated readings represent repeated measurements and must each be considered. Determine how many readings are at least the alert floor.

Problem

Implement a function that counts the readings whose value is greater than or equal to the given alert floor. Check every reading independently, including duplicates, negative values, zero, and readings exactly equal to the floor. If the batch is empty, return zero. The scan must use linear time and constant auxiliary space.

Examples

Example 1
Input: alert_floor = 7readings = [3, 7, 7, 2, 10]
Output: 3
Explanation: The readings 7, 7, and 10 meet the floor of 7, so the executed result is 3.
Example 2
Input: alert_floor = 0readings = [-5, 0, 4, -2, 9]
Output: 3
Explanation: The readings 0, 4, and 9 meet the floor of 0, so the executed result is 3.
Example 3
Input: alert_floor = 12readings = []
Output: 0
Explanation: The input has no readings, so the executed result is 0.

Constraints

  • 0 <= len(readings) <= 100000
  • -1000000 <= readings[i] <= 1000000 for every i
  • -1000000 <= alert_floor <= 1000000
  • Types: readings is int[], alert_floor is int; result is int

Function signature

def count_alert_readings(readings: list[int], alert_floor: int) -> int
readings list[int]
The integer telemetry readings collected in the batch.
alert_floor int
The inclusive minimum value required for a reading to qualify.
returns int
The number of readings whose value is greater than or equal to alert_floor.

Adapted from MBPP problem task_66 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Approved · t3-abs_520_v314 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1