Self Generated Solution
IntuitionWe are given three side lengths and need to determine what type of triangle they form. A valid triangle must satisfy the triangle inequality rule (sum
# Intuition
We are given three side lengths and need to determine what type of triangle they form. A valid triangle must satisfy the **triangle inequality rule** (sum of two smaller sides must be greater than the largest side). Based on side lengths, a triangle can be:  
- **Equilateral** → All three sides are the same.  
- **Isosceles** → Exactly two sides are the same.  
- **Scalene** → All sides are different.  
- **None** → If it doesn’t satisfy the triangle inequality, it’s not a triangle.  

# Approach
1. **Sort** the sides to make comparisons easier.  
2. **Check for an equilateral triangle** (all sides are equal).  
3. **Verify if it forms a valid triangle** using the triangle inequality rule. If not, return `"none"`.  
4. **Check for isosceles** (at least two sides are the same).  
5. **If none of the above, it must be scalene** (all sides different and valid).  

# Complexity
- Time complexity:
- Sorting a 3-element array takes **O(1)** (constant time).  
- Comparisons are **O(1)**.  
- **Total: O(1) (constant time).**  

- Space complexity:
- Only a few extra variables are used.  
- **Total: O(1) (constant space).** 

# Code
```java []
class Solution {
    public String triangleType(int[] nums) {

        Arrays.sort(nums);
        if(nums[0]==nums[1] && nums[1]==nums[2]){
            return "equilateral";
        }
        else if(nums[0]+nums[1]<=nums[2]){
            return "none";
        }
        else if(nums[0]==nums[1] || nums[1]==nums[2] || nums[2]==nums[0]){
            return "isosceles";
        }
        else if(nums[0] != nums[1] && nums[1] != nums[2] && (nums[0] + nums[1] > nums[2]) ){
            return "scalene";
        }
        else{
            return "none";
        }
    }
}

// class Solution {
//     public String triangleType(int[] nums) {

//         // sort(nums.begin(), nums.end());
//         Arrays.sort(nums);

//         if(nums[0] + nums[1] <= nums[2]){
//             return "none";
//         }      
//         else if(nums[0]==nums[2]){                          // all elements are sorted first==third
//             return "equilateral";
//         }
//         else if(nums[0]==nums[1] || nums[1]==nums[2]){     // all elements are sorted either=> first==second or second==third
//             return "isosceles";
//         }
//         else{
//             return "scalene";
//         }
//     }
// }


// Aryan Mittal

// Time Complexity Analysis
// The algorithm first sorts the array using Arrays.sort(nums), which has a worst-case time complexity of O(n log n).
// After sorting, it performs a few conditional checks, all of which are O(1) operations.
// Therefore, the overall time complexity is O(n log n) due to the sorting step.
// Space Complexity Analysis
// The algorithm sorts the array in place, meaning no extra space is required for sorting.
// It only uses a few extra variables for comparisons and returning results, all of which take O(1) space.
// Therefore, the overall space complexity is O(1).
```
['Java']