Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 2 you can also use imports, for example: import java.util. A5]20 Triplet (0, 2

ID: 3756102 • Letter: 1

Question

1 2 you can also use imports, for example: import java.util. A5]20 Triplet (0, 2, 4) is a triangle and its perimeter equals 10+ 5+8- 23. There is no other triangle in this array with a larger perimeter Write a function 4 // you can write to stdout for debugging purposes, e.g 5 I System.out.println("this is a debug message"; 6 import java.util.Arrays; 7 class Solution class Solution public int solution(int[ A) that, given an array A of N integers, returns the maximum perimeter of any triangle in this array. The function should return -1 if there are no triangles For example, given: AI010 A12 A[2]5 All changes saved Test Output Example test [10, 2, 5, 1, 8, 20] WRONG ANSWER (got -1 expected 23) Run Tests the function should return 23, as explained above

Explanation / Answer

class Solution { public int solution(int[] A) { int s1, s2, s3, max = -1; for (int i = 0; i