## Microsoft Interview Question

• 0

Team: Office
Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
7
of 7 vote

``````if(a+b <= c || b+c<=a || a+c<=b )
return 0;
else if(a == b && b== c)
return 1;
else if(a==b || b==c || c==a)
return 2;
else
return 3;``````

Comment hidden because of low score. Click to expand.
1
of 1 vote

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);

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````int test(int a, int b, int c){
if(a < 0 || b < 0 || c < 0)
return 0;
if(a+b <= c || a+c <= b|| b+c <= a)
return 0;
if(a == b && b == c){
return 1;
}else if(a == b || b == c){
return 2;
}else{
return 3;
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

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;``````

Comment hidden because of low score. Click to expand.
0

@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

Comment hidden because of low score. Click to expand.
0

You can check here the rules for three sides(not points) to form a triangle wikihow.com/Determine-if-Three-Side-Lengths-Are-a-Triangle

Comment hidden because of low score. Click to expand.
0
of 0 vote

After this code ... I was asked to provide the inputs to test if this code is working or note.

main stress was on conditions for Isoceles triangle.

Comment hidden because of low score. Click to expand.
0

Don't forget guys, for any triangle, any two sides (a, b for instance) must add together to a distance longer than the third side (a+b > c), otherwise it is not a triangle...

Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Provide negative values then conditions like (a+b <= c) will fail to check
2) Provide floating values also a=2.3,b=2.8 then if you took as integer then a==b, but logically wrong

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.