## Microsoft Interview Question

**Team:**Office

**Country:**United States

**Interview Type:**In-Person

If one or more of the values in zero or negative, need to return 0.

One is also asked to provide test cases. If the method has a signature:

int testTriangle(int a, int b, int c);

Positive TC's:

testTriangle(3, 3, 3);

testTriangle(3, 3, 4);

testTriangle(3, 4, 5);

Negative TC's:

testTriangle(3, 4, 8);

testTriangle(0, 0, 0);

testTriangle(-3, -3, -3);

Input : a , b, c :

```
cnt = 0;
if(a == b) cnt++;
if(a == c) cnt++;
if(b == c) cnt++;
if(a+b <= c || b+c <= a || a+c <= b) return 0; //thanks vik (I changed && in || and added <=)
if(cnt >= 2) return 1;
if(cnt == 1) return 2;
if(cnt == 0) return 3;
```

@Kamy in the if condition

if(a+b < c && b+c < a && a+c < b) return 0;

can this be ever true?

I dont think for 3 +ve real numbers a,b,c they can ever satisfy your condition

However you can fix the code by putting

if(a+b = c || b+c = a || a+c = b) return 0;

which is the case when the 3 points lie on a line

- Anonymous January 29, 2013