710019. Can Make Triangle

Easy

Here is the detailed Markdown blog post for the "Can Make Triangle" problem:

Can Make Triangle

Summary

Given a set of integers, determine whether it's possible to form a triangle with three sides having lengths equal to these integers. This problem involves geometric concepts and simple mathematical calculations.

Detailed Explanation

To solve this problem, we need to check if the given numbers can form a valid triangle or not. A triangle is said to be valid when the sum of the lengths of any two sides is greater than the length of the third side. We can use this property to determine whether it's possible to form a triangle.

Here's the step-by-step breakdown:

  1. Sort the given numbers in ascending order.
  2. Check if the longest side (let's call it a) has a length less than or equal to twice the length of the second longest side (b). If this condition is not met, we can't form a triangle and return false.
  3. If the above condition is satisfied, check if the sum of a and b is greater than the length of the third side (c). If this condition is also satisfied, it means we can form a valid triangle.

Here's an ASCII art diagram to illustrate the conditions:

  a (longest)
  |
  |_____b
  |
  c (shortest)

Time complexity: O(n log n) due to sorting. Space complexity: O(1) as we only need a constant amount of space.

Optimized Solutions

Java

View on GeeksforGeeks
public boolean canMakeTriangle(int[] nums) {
    Arrays.sort(nums);
    for (int i = 0; i < nums.length - 2; i++) {
        if (nums[i] + nums[i + 1] <= nums[i + 2]) {
            return false;
        }
    }
    return true;
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.