IQR Outlier Detection

Easy
~15 min
code completion

IQR Outlier Detection

The interquartile range (IQR) method flags outliers without assuming any labels or a specific distribution. It is robust because the IQR itself is unaffected by the very extremes it detects.

The rule:

1. Compute and

2.

3. Lower fence:

4. Upper fence:

5. Any value outside the fences is an outlier

Example: arr = [1, 2, 3, 4, 100]

  • , , IQR
  • Fences:
  • 100 > 7 → outlier
  • Your task:

    Implement iqr_outlier_mask(arr) that returns an integer array where 1 = outlier and 0 = normal.

    Example Tests

    Single high spike flagged at position 4

    Input: {"arr":[1,2,3,4,100]}

    Expected: [0,0,0,0,1]

    All identical values: IQR is zero, no outliers

    Input: {"arr":[10,10,10,10,10]}

    Expected: [0,0,0,0,0]

    Single low outlier flagged at position 0

    Input: {"arr":[-100,2,3,4,5]}

    Expected: [1,0,0,0,0]

    Sign in to solve this problem

    You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.