import java.util.*;

public class Arraz {

    public int sumValuesOfArray(int[] arr) {
        int sum = 0;

        for (int i : arr) {
            sum += i;
        }

        return sum;

    }

    public double sumDoublesOfArray(double[] arr) {
        double sum = 0;

        for (double d : arr) {
            sum += d;
        }

        return sum;

    }


    public int averageOfArray(int[] arr) {
        int sum = 0;

        for (int i : arr) {
            sum += i;
        }

        return (sum / arr.length);
    }


    public double doubleAverageOfArray(double[] arr3) {

        double sum = 0;

        for (double i : arr3) {
            sum += i;
        }

        return (sum / arr3.length);

    }


    public boolean containsValue(int[] arr, int value) {

        for (int i : arr) {
            if (i == value) {
                return true;
            }
        }
        return false;
    }


    public int[] reverseArray(int[] array1) {
        int[] array2 = new int[array1.length];

        for (int i = 0; i < array1.length; i++) {
            array2[array1.length - 1 - i] = array1[i];
        }

        return array2;
    }

    public int[] insertIntoArray(int[] array, int pos, int value) {

        int[] arr = new int[array.length + 1];
        int count = 0;

        for (int i = 0; i < array.length; i++) {
            if( i == pos - 1 ){
                arr[count] = value;
                count++;
            }

            arr[count] = array[i];
            count++;
        }
        return arr;
    }

    public Integer[] removeDupesFromArray(Integer[] array) {
        Set<Integer> list = new HashSet<Integer>();
        int count = 0;

        for (Integer i : array){
            list.add(i);
        }

        int len = list.size();
        Integer[] newArr = new Integer[len];

        for (Integer i : list){
            newArr[count] = i;
            count++;
        }

        return newArr;
    }

    public Integer find2ndLargestValueFromArray(Integer[] array) {
        if (array.length < 2){
            return -1;
        }

        Integer[] arr = new Integer[array.length];
                Arrays.sort(array);

        return array[array.length - 2];
    }

    public ArrayList<Integer> makeMeAnArrayListFromArray(Integer[] array) {
        ArrayList<Integer> al = new ArrayList<Integer>();

        for (Integer i : array){
            al.add(i);
        }

        return al;
    }

    public Integer[] makeMeAnArrayFromArrayList(ArrayList<Integer> al) {
        Integer[] array = new Integer[al.size()];
        int count = 0;
        for (Integer i : al){
            array[count] = i;
            count++;

        }

        return array;
    }

    public boolean check2ArraysForEqual(String[] str1, String[] str2) {
        return Arrays.equals(str1, str2);
    }

    public Integer averageArrayWithoutMaxMin(Integer[] arr1) {

//        findMaxMinOfArray((Double) arr1);

        return null;
    }

    public class OddEven {
        public int odds;
        public int evens;

        public int getOdds(int[] array) {
            return odds;
        }

        public int getEvens(int[] array) {
            return evens;
        }


        public void getOddEvensOfArray(int[] array1) {
            for (int i : array1) {
                if (i % 2 == 0) {
                    evens += 1;
                } else {
                    odds += 1;
                }
            }
        }
    }

    public Integer[] copyArrayByIterator(Integer[] array1) {

        int i = 0;
        Integer[] newArr = new Integer[array1.length];
        Iterator<Integer> iterator = Arrays.asList(array1).iterator();

        while (iterator.hasNext()) {
            newArr[i] = iterator.next();
            i++;
        }
        return newArr;
    }


    public int findIndexOf(int[] array1, int value) {
        int count = 0;
        for (int i : array1) {
            if (i == value) {
                return count;
            }
            count++;
        }
        System.out.println("Value of " + value + " does not exist");
        return -1;
    }

    public Integer[] copyArrayByLoop(Integer[] array3) {
        Integer[] intArr = new Integer[array3.length];

        for (int j = 0; j < array3.length; j++) {
            intArr[j] = array3[j];
        }
        return intArr;
    }

    public Integer[] removeElementFromArray(Integer[] array, Integer value) {
        Integer[] arr = new Integer[array.length-1];
        int count = 0;
        for (Integer i: array){
            if (i != value){
                arr[count] = i;
                count++;
            }
        }
        return arr;
    }


    public class MaxMin {
        public int max;
        public int min;

        public int getMax() {
            return max;
        }

        public int getMin() {
            return min;
        }

        public void setMax(int max) {
            this.max = max;
        }

        public void setMin(int min) {
            this.min = min;
        }
    }

    public MaxMin findMaxMinOfArray(int[] array) {
        MaxMin mn = new MaxMin();

        mn.setMax(array[0]);
        mn.setMin(array[0]);

        for (int i : array){
            if ( i > mn.getMax() ){
                mn.setMax(i);
            }

            if ( i < mn.getMin() ){
                mn.setMin(i);
            }
        }

        return mn;
    }
}
