C++ || Easy Solution || O(n log(n))
Approach\nSTEP-1: Sort the vector\nSTEP-2: Traverse the vector from last elements, check if last 3 elements can for a triangle, if true return sum of elements.\
# Approach\nSTEP-1: Sort the vector\nSTEP-2: Traverse the vector from last elements, check if last 3 elements can for a triangle, if true return sum of elements.\n\n# Complexity\n- Time complexity: O(n log(n))\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int largestPerimeter(vector<int>& n) {\n        sort(n.begin(), n.end());\n\n        for(int i = n.size()-3; i >= 0; i--)\n        {\n            if(n[i] + n[i+1] > n[i+2])\n            {\n                return n[i] + n[i+1] + n[i+2];\n            }\n        }\n\n        return 0;\n    }\n};\n```
['Array', 'Math', 'Sorting', 'C++']