Kaseya Interview Question
Java DevelopersCountry: India
Interview Type: In-Person
nem, the isRightTriangle does not work for large values.Example:
a,b,c 30000 40000 50000
squares 900000000 1600000000 2147483647
the squares overflow int values silently.
Something like
long a_squared = (long) sides[0] * sides[0]; works for larger values. You could also use 'scalene' for 'None' in the output.
The solution bellow assumes only integers will be used for triangle side length.
An equiliteral triangle has all 3 sides equal
Example 3 3 3
An isosceles trianglle has 2 sides equal
Example 3 2 3
A rightangle triangle has one side squared equal to the sum of the other two sides square (Pythagoras theorem)
Example 3 4 5 (3*3 + 4*4 = 5*5)
- nem September 12, 2014