Company: IBM
Difficulty: medium
Sort Triangles by Area Problem Description You are given 'n' triangles and their sides a, b and c. Print them in the same style but sorted by their areas from the smallest one to the largest one. It is guaranteed that all the areas are different. The best way to calculate an area of a triangle with sides a, b and c is by using the Heron's formula: S = sqrt (p * (p - a) * (p - b) * (p - c)) where p = (a + b + c)/2 Examples Example 1: Input: 3 7 24 25 5 12 13 3 4 5 Output: 3 4 5 5 12 13 7 24 25 Explanation: For the triangle with sides a=7, b=24, c=25: p = (7 + 24 + 25) / 2 = 56 / 2 = 28 Area S = sqrt(28 * (28 - 7) * (28 - 24) * (28 - 25)) = sqrt(28 * 21 * 4 * 3) = sqrt(7056) = 84 For the triangle with sides a=5, b=12, c=13: p = (5 + 12 + 13) / 2 = 30 / 2 = 15 Area S = sqrt(15 * (15 - 5) * (15 - 12) * (15 - 13)) = sqrt(15 * 10 * 3 * 2) = sqrt(900) = 30 For the triangle with sides a=3, b=4, c=5: p = (3 + 4 + 5) / 2 = 12 / 2 = 6 Area S = sqrt(6 * (6 - 3) * (6 - 4) * (6 - 5)) = sqrt(6 * 3 *