KatInterview

Classify Temperatures into Three Weather Bands

Arrays & HashingAuto-graded · 18 test cases
EasyAuto-gradedArrays & Hashingarrayscountingboundary conditions

Last updated

Tests careful boundary handling by bucketing integer temperatures into cold, mild, and hot ranges and returning the three counts in order.

A weather station records daily high temperatures (in °F) for a set of locations. Your job is to sort those readings into three weather bands and report how many locations fall into each one.

The bands are defined as follows:

  • Cold: temperature strictly below 50
  • Mild: temperature from 50 up to and including 80
  • Hot: temperature strictly above 80

Given a list of integer temperature readings, return a list of three integers representing the count of cold readings, mild readings, and hot readings, in that order.

Rules

  • A reading of exactly 50 or exactly 80 belongs to the mild band.
  • A reading of exactly 81 belongs to the hot band.
  • Every reading falls into exactly one band, so the three counts always sum to the total number of readings.
  • An empty list of readings must return [0, 0, 0].

Constraints

  • 0 <= len(temps) <= 100000
  • 0 <= temps[i] <= 100

Examples

Example 1

Input: classify_temperatures([30, 50, 65, 80, 81, 95, 49])

Output: [2, 3, 2]

Example 2

Input: classify_temperatures([100, 100])

Output: [0, 0, 2]

Example 3

Input: classify_temperatures([])

Output: [0, 0, 0]

Hints

Hint 1

A single pass through the list is all you need — track one counter per band as you go.

Hint 2

Write your comparisons as an if / elif / else chain so each reading increments exactly one counter. Three separate if statements risk counting a boundary value twice.

Hint 3

The trickiest inputs are the exact boundary values: 49, 50, 80, and 81. Make sure your comparison operators (< vs <=) place each of those in the right band, then check the empty list as a final edge case.