PRECISE EXPLANATION OF WHY SORT() USED FROM SCRATCH
Explanation\n\n    Assume a = 2, b = 1, c = 2\n\nNow we have to find out if it\'s possible to make a triangle using a,b,c.\n\nIF \'EVERY\' TWO SIDE\'S SUMMATION
## Explanation\n```\n    Assume a = 2, b = 1, c = 2\n\nNow we have to find out if it\'s possible to make a triangle using a,b,c.\n\nIF \'EVERY\' TWO SIDE\'S SUMMATION FROM (a,b,c) > THIRD SIDE, THEN IT\'S POSSIBLE\n\na + b > c          a + c > b           b + c > a\n2 + 1 > 2          2 + 2 > 1           1 + 2 > 2\n3 > 2              4 > 1               3 > 2\n\nDoesn\'t matter which 2 side we pick, it\'s summation always strictly larger than\nthe third side. BUT IF ANY TWO SIDE\'S SUMMATION WAS NOT LARGER THAN THE THIRD\nSIDE, THEN THE TRIANGLE IS NOT POSSIBLE!\n\nAssume a = 1, b = 1, c = 2\n\na + c > b       b + c > a       BUT   a + b > c ?\n1 + 2 > 1       1 + 2 > 1             1 + 1 > 2 ? \n                                      FALSEEEEEE\n\nHence, with a = 1, b = 1, c = 2 making triangle is not possible!\n\nSo first we have to find if there is one single variation ( from a+b>c, \na+c>b, b+c>a) is FALSE or not.\n\nLook the last example where if a and b both 1 but c = 2, means if  we sum c with\neither a or b then it will be always larger than the third side because \nTHE VALUE OF C IS LARGER THAN A AND B, SO IT\'S ALREADY LARGER AND IF WE SUM IT \nWITH A OR B THEN IT WILL BE MORE LARGER THAN THE THIRD SIDE (A/B).\nSO WE WILL DO SUM OF THE FIRST TWO SMALL VALUES, IF THEIR SUM > THIRD SIDE, \nTHEN WE CAN CLEARLY SAY THE OTHER TWO VARIATIONS (a+c>b & b+c>a) IS TRUE!\n\na, b = first two small values in sorted order and c = equal or larger than b\n\nAssume a, b, c = 1, 2, 2 (in sorted order)\nsince a + b > c then no need to check for a + c > b   &   b + c > a\n      1 + 2 > 2                           1 + 2 > 2       2 + 2 > 1\n      3 > 2\n\nalso say a, b, c = 1, 1, 1\n                   a + b > c so also a + c > b    b + c > a\n                   1 + 1 > 1         1 + 1 > 1    1 + 1 > 1\n                   2 > 1\n    \nSo the key point is for every three value (a,b,c) we need to check ONLY \nTHE FIRST 2 SMALL VALUES I.E. if a+b>c then we will compare the summation \nof those a,b,c with the rest.. " ONLY THE FIRST 2 SMALL VALUES "\nSO THAT MEANS WE NEED TO SORT THE list/vector FIRST! Then for each index \n(except the last 2) just check if nums[i] + nums[i+1] > nums[i+2]...\n```\nThere is 3 type variation I showed, so in order to check JUST ONE, we need to\nsort it first.\n```CPP []\nclass Solution \n{\npublic:\n    int largestPerimeter(vector<int>& nums) \n    {\n        sort(begin(nums),end(nums));\n        int sum = 0, size = nums.size()-2, a, b, c;\n        for(int i=0; i<size; i++)\n        {\n            a = nums[i], b = nums[i+1], c = nums[i+2];\n            if(a+b>c)\n                sum = max(a+b+c, sum);\n        }\n        return sum;\n    }\n}; \n```\n```Python []\nclass Solution:\n    def largestPerimeter(self, nums: List[int]) -> int:\n        nums.sort()\n        return max( sum(nums[i:i+3]) if nums[i]+nums[i+1] > nums[i+2] else 0 for i in range(len(nums)-2) )\n```\n```\nTime complexity  : O(sort)\nSpace complexity : O(sort)\n\nO(sort) as the sort function is hybrid sort, so it depends which sorting \ntechnique is being used in the sort function. \n```\n## If any of the information was wrong please leave a comment with correctness. If the post was helpful an upvote will really make me happy:)\n
['C++', 'Python3']