All points except for one lie on a line. Which one is the outlier?

Example:

You are given a list of x-y pairs in a column like this:

pts = [ 0 1 0 2 3 2 0 3 0 4 ]

You would return the number 3, since the third point is the only one that is non-collinear with the other points. All the others are on the y-axis.

outlier = 3

Justin
on 29 Apr 2014

The instructions were a bit confusing at first. It would have been better to say "Find the row number of the outlying point."
Also, using the third row as an answer and a 3 in a column of zeros makes it seem like the intent was to provide unclear instructions. (Or they are just used to writing college textbooks ;) )

Wenwu
on 8 Jan 2015

The test set cases 2,3 seems to have two outliers for each case. Please check it

2 Comments

Hoai Tran Quoc
on 13 Oct 2016

Very interesting, why the test# 3 is not passed. It turned out that the two number
(x4-x1)*(y2-y1) is not the same as (y4-y1)*(x2-x1) due to floating point. I have to compare the subtraction with 10*eps.

Hoai Tran Quoc
on 14 Oct 2016

Very interesting. I could not understand why I had not passed the test# 3. It turned out that the two number (x4-x1)*(y2-y1) and (y4-y1)*(x2-x1) are not the same due to floating point. My choice is to compare the absolute difference with 10*eps.

1 Comment

Francisco
on 27 May 2016

I'll try to improve it!

1 Comment

ABDELRAHMAN
on 30 Jan 2016

all tests are solved test3, i don't know what is the problem

2 Comments

Daniel Pereira
on 23 Mar 2015

I'm sorry for this :(

Daniel Pereira
on 23 Mar 2015

I got it on solution 600827.
http://www.mathworks.com/matlabcentral/cody/problems/661-spot-the-outlier/solutions/600827

1 Comment

Jean-Marie Sainthillier
on 20 Sep 2012

Doesn't work with outlier in first position.

1 Comment

Christopher
on 11 Jun 2012

Could have been MUCH smaller, but corrcoef doesn't like x=0 the first test case.

**Tags**

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
5 players like this problem

5 players like this problem