Find integer that can make a triangle

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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s