`{"id":"bd5d9e50-f4b2-45a3-9ab8-cbed4549c467","name":"Largest Perimeter Triangle","description":"Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"3 &lt;= nums.length &lt;= 10^4\r\n1 &lt;= nums[i] &lt;= 10^6","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint largestperimeter(vector<int>& arr)\n{\n \n return 0;\n}\nint main()\n{\n int n;\n cin>>n;\n \n vector<int> arr(n);\n for(int i=0;i<n;i++)\n {\n cin>>arr[i];\n \n }\n \n int x=largestperimeter(arr);\n cout<<x;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int largestPerimeter(int[]nums) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]nums = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n nums[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(largestPerimeter(nums));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n3 6 2 3","sampleOutput":"8","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"5fd9df27-f375-486b-9001-d2fd37059206","name":"Largest Perimeter Triangle","slug":"largest-perimeter-triangle","type":1}],"next":{"id":"ee758419-aeeb-4df3-8b39-515e9c1eac88","name":"Largest Perimeter Triangle","type":3,"slug":"largest-perimeter-triangle"},"prev":{"id":"8a6b6c0d-95f4-40de-9a37-5067e8f5d555","name":"Matrix Cells In Distance Order MCQ","type":0,"slug":"matrix-cells-in-distance-order-mcq"}}}`

# Largest Perimeter Triangle

Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.

`{"id":"bd5d9e50-f4b2-45a3-9ab8-cbed4549c467","name":"Largest Perimeter Triangle","description":"Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"3 &lt;= nums.length &lt;= 10^4\r\n1 &lt;= nums[i] &lt;= 10^6","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint largestperimeter(vector<int>& arr)\n{\n \n return 0;\n}\nint main()\n{\n int n;\n cin>>n;\n \n vector<int> arr(n);\n for(int i=0;i<n;i++)\n {\n cin>>arr[i];\n \n }\n \n int x=largestperimeter(arr);\n cout<<x;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int largestPerimeter(int[]nums) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]nums = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n nums[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(largestPerimeter(nums));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n3 6 2 3","sampleOutput":"8","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"5fd9df27-f375-486b-9001-d2fd37059206","name":"Largest Perimeter Triangle","slug":"largest-perimeter-triangle","type":1}],"next":{"id":"ee758419-aeeb-4df3-8b39-515e9c1eac88","name":"Largest Perimeter Triangle","type":3,"slug":"largest-perimeter-triangle"},"prev":{"id":"8a6b6c0d-95f4-40de-9a37-5067e8f5d555","name":"Matrix Cells In Distance Order MCQ","type":0,"slug":"matrix-cells-in-distance-order-mcq"}}}`

Editor

# Largest Perimeter Triangle

easy

Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.

## Constraints

3 <= nums.length <= 10^4 1 <= nums[i] <= 10^6

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 3 6 2 3```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}8`

Discussions

Show Discussion

Related Resources