Python Solution with explanation.
Intuition\n Describe your first thoughts on how to solve this problem. \nWe\'ve to find the largest perimeter of triangle & that\'s why we need to first sort th
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe\'ve to find the largest perimeter of triangle & that\'s why we need to first sort the list and loop from behind.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst we\'ll sort the program & take j as size of nums minus 3 and we\'ll decrease the value after each loop and similarly take i as the last element and decrease the value after each loop.\n\nTill the j is greater than 0, go in the nums list. If nums[j]+nums[j+1]>nums[i] then return the sum of all these otherwise go on in the loop and will return 0 if no such condition found.\n\n==========================================================\n\nLet\'s understand this with an example :-\n\nnums = [3,6,2,3]\n\nSo, we\'ll first sort the array and it will now look like \nnums = [2,3,3,6]\n\nNow, we\'ll take i as the last element of the list and j as the (length of list-3) index.\n\n \n![image.png](https://assets.leetcode.com/users/images/344f6d8f-6347-4a5f-acde-7219b2a4a83e_1665580667.2809658.png)\n\nSo j will point to 3 and i will point to 6.\n\nNow, we\'ll check the first condition if nums[j]+nums[j+1]>nums[i] i.e., if 3+3>6, so that is false so we\'ll decrement both the value of i and j by 1.\n\nNow, i will start pointing to 3 and j will point to 2.\n\n\n![image.png](https://assets.leetcode.com/users/images/3029c91b-08bc-425b-9d17-74069a901eca_1665580695.550933.png)\n\nNow, we\'ll check the condition if nums[j]+nums[j+1]>nums[i] i.e., if 2+3>3, so that is true as 5>3 so we\'ll return the sum of all these like 2+3+3 i.e., we\'ll return 8.\n\nAnd this is how we\'ll look in the list for every element.\n\n**Corner Case :-**\n\nAnd suppose if this also won\'t work like if suppose the list is like 1 2 3 6 and for every case this condition is false, like 2+3>6 is false and similarly 1+2>3 is also false so in that case we\'ll return 0.\n\n==========================================================\n\n# Complexity\n- Time complexity: O(n log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!--Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def largestPerimeter(self, nums: List[int]) -> int:\n        nums.sort()\n        n = len(nums)\n        \n        i = n-1\n        j = n-3\n\n        while(j>=0):\n            if(nums[j]+nums[j+1]>nums[i]):\n                return nums[j]+nums[j+1]+nums[i]\n            i=i-1\n            j=j-1\n        return 0\n```
['Python3']