Find integer that can make a triangle | Hello World
Given an integer array, find if there are elements that can make a legal triangle.
Assume we have A, B, C equals to the length of the each vertex and satisfy condition A + B > C, B + C > A, and A + C > B.
To find the A, B and C, assume we pick one element as A, then we will need to have B + C > A, where A is the longest vertex in the triangle. So we can simply sort the input array, and for every element, we check if the previous 2 element can form an triangle with the current element.
However if we want to output all the possible triplet, then I can only think of a brute force method
Read full article from Find integer that can make a triangle | Hello World
No comments:
Post a Comment