Compute Z-Score of a Single Observation

Basics
BasicsZ-ScoreNormal DistributionGoogleMetaJane Street

Problem

Given an observation value, population mean, and strictly positive std > 0, implement z_score(value, mean, std) returning z=value−meanstdz = \frac{\text{value} - \text{mean}}{\text{std}} as a Python float.

Why It Matters: Z-scores tell you how many standard deviations a point sits above or below the mean—powering anomaly detection, hypothesis testing, and feature standardization.

Function Signature

def z_score(value: float, mean: float, std: float) -> float:

Sample Input & Output

Example 1: Above the Mean

Input:

value = 85.0, mean = 70.0, std = 10.0

Expected Output:

1.5

Explanation: (85 - 70) / 10 = 1.5 standard deviations above the mean.

Example 2: Below the Mean & At the Mean

Input:

value = 60.0, mean = 70.0, std = 5.0

Expected Output:

-2.0

Explanation: (60 - 70) / 5 = -2.0 standard deviations below the mean; if value == mean, z = 0.0.

Constraints & Edge Cases

  • Return float z-score (std > 0).
  • std is guaranteed strictly positive (> 0).
  • Negative z-scores indicate observations below the mean.

Constraints & Evaluation Criteria

  • Return `float` z-score (`std > 0`).

Hints

Python 3
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
value=130, mean=100, std=15
Expected Output / Criteria
2.0