Posts Type of Triangle
Post
Cancel

Type of Triangle

Type of Triangle

  • URL : https://www.hackerrank.com/challenges/what-type-of-triangle/problem
  • Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:
  • Equilateral: It’s a triangle with 3 sides of equal length.
  • Isosceles: It’s a triangle with 2 sides of equal length.
  • Scalene: It’s a triangle with 3 sides of differing lengths.
  • Not A Triangle: The given values of A, B, and C don’t form a triangle.
  • MySQL, Oracle Solution
1
2
3
4
5
6
7
8
select 
    case 
        when a + b <= c or a + c <= b or b + c <= A then 'Not A Triangle'
        when a = b and a = c then 'Equilateral'
        when a = b or a = c or b = c then 'Isosceles'
        else 'Scalene'
    end
from triangles;
This post is licensed under CC BY 4.0 by the author.