1

Outlier Detection with IQR

Unsolved
Fundamentals

Difficulty: 2 | Problem written by bilaldadanlar
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

One of the widely used outlier detection methods for univariate data is the IQR method. 

IQR, or Inter-Quartile Range, is the difference between third quartile and first quartile of your data (75th percentile and 25th percentile respectively).

Lower and upper bounds are calculated as Q1 - 1.5 IQR and Q3 + 1.5 IQR respectively.

Write a function that takes a 1D numeric NumPy array and returns a 1D array consistting of the outliers that are greater than upper bound or less than lower bound calculated.

Sample Input:
<class 'numpy.ndarray'>
data: [ 0 50 53 55 57 60 98]

Expected Output:
<class 'numpy.ndarray'>
[ 0 98]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Unde sint quibusdam delectus aspernatur quas, optio asperiores sunt error voluptas odit aspernatur? Dolorum omnis non delectus aut debitis iure distinctio maxime, quasi quidem aperiam quisquam earum reiciendis obcaecati?

Sint voluptas est tenetur, delectus sed exercitationem officia quidem excepturi eaque ipsa sapiente, sapiente rerum officia deserunt itaque, nemo quia perspiciatis, dignissimos sed assumenda nobis vitae expedita enim eum. Atque nesciunt unde dicta vero blanditiis, vero voluptates nobis aliquid dignissimos ipsum tenetur rerum incidunt facere eum, doloremque repellendus odio similique tempore quam hic possimus? Enim deleniti unde atque, rem ratione error nemo illo ex sapiente aspernatur nam doloremque officia, minima enim corporis amet incidunt excepturi ducimus obcaecati sunt reiciendis quidem?

Maiores modi odio hic repellendus pariatur, incidunt fugit exercitationem illo, animi ratione distinctio eos? Commodi officiis ratione voluptas voluptatum, quisquam facilis earum laborum ipsam enim eligendi hic asperiores quia culpa, nihil porro repellat nesciunt.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)