[C++] Easy Approach with Explanation !!
Hola Coders!!\n\nThere is a property of triangle where if two sides is greater then the third side we can get the larget perimeter triangle, to getting the lage
##### Hola Coders!!\n\nThere is a property of triangle where **if two sides is greater then the third side** ***we can get the larget perimeter triangle***, to getting the lagest triangle we sort the array and start from the right most corner that is largest element in the array. Using this logic we first run the loop from **length of vector -1** to the **third element** *(after third element triangle not possible)*, we keep on decreasing loop value by **1**, use three variables to store values from the vetor to compare, *if we found the right combination* we return the value, if not then we *continue iteration till the end,* after completing iteration of the loop we simply **return 0**.\n\n```\nclass Solution {\npublic:\n    int largestPerimeter(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        for(int i=nums.size()-1;i>=2;i--)\n        {\n            int a=nums[i-2];\n            int b=nums[i-1];\n            int c=nums[i];\n            if(a+b>c)\n            {\n                return a+b+c;\n            }\n            \n        }\n        return 0;\n    }\n};\n```\nWe can further optimize it by not storing values in the variables and can directly compare the values to the array in the if condition that way we can optimize the space. \n```\nclass Solution {\npublic:\n    int largestPerimeter(vector<int>& nums) {\n        sort(nums.begin(),nums.end());\n        for(int i=nums.size()-1;i>=2;i--)\n        {\n           \n            if(nums[i-2]+nums[i-1]>nums[i])\n            {\n                return nums[i-2]+nums[i-1]+nums[i];\n            }\n            \n        }\n        return 0;\n    }\n};\n\n```
['C', 'C++']