@@ -0,0 +1,1141 @@
+// We assume the following:%0A// - input has at least 3 elements%0A// - input length is always odd%0A// - numbers are from 1 to n without any gaps or duplicates%0A//%0A// Examples:%0A// %5B3, 9, 1, 5, 8, 2, 4, 11, 7, 6, 10%5D; // answer: 4%0A// %5B3, 9, 8, 5, 1, 2, 7, 11, 4, 6, 10%5D; // answer: 2%0A// %5B2, 4, 3, 5, 1, 6, 7%5D; // answer: 4%0A// %5B2, 3, 6, 1, 7, 5, 9, 4, 8%5D; // answer: 5%0A%0Aclass GFG %7B%0A  private static int tripletMean(int%5B%5D arr) %7B%0A    int%5B%5D tmp = new int%5Barr.length%5D;%0A    System.arraycopy(arr, 0, tmp, 0, arr.length); // so we don't modify input%0A%0A    int len = arr.length;%0A%0A    while (len %3E 1) %7B%0A      int i = 0;%0A      while (i %3C len - 2) %7B%0A        tmp%5Bi%5D = mean(tmp%5Bi%5D, tmp%5Bi + 1%5D, tmp%5Bi + 2%5D);%0A        i++;%0A      %7D%0A      len -= 2;%0A    %7D%0A    return tmp%5B0%5D;%0A  %7D%0A%0A  private static int mean(int a, int b, int c) %7B%0A    int%5B%5D tmp = new int%5B%5D %7Ba, b, c%7D;%0A    java.util.Arrays.sort(tmp);%0A    return tmp%5B1%5D;%0A  %7D%0A%0A  public static void main (String%5B%5D args) %7B%0A    // int%5B%5D arr = new int%5B%5D %7B3, 9, 1, 5, 8, 2, 4, 11, 7, 6, 10%7D; // answer: 4%0A    int%5B%5D arr = new int%5B%5D %7B3, 9, 8, 5, 1, 2, 7, 11, 4, 6, 10%7D; // answer: 2%0A    System.out.println(tripletMean(arr));%0A  %7D%0A%7D%0A

add solution