• + 0 comments

    JAVA

    static int flatlandSpaceStations(int n, int[] c) {

        ArrayList<Integer> arrayList = new ArrayList<>();
        for(int i=0;i<n;i++){
            int k=0;
            int res = Integer.MAX_VALUE;
            while(k<c.length){
                int res1 = c[k]-i;
                if(res1<0){
                    res1 = 0-res1;
                }
                if(res>res1){
                    res = res1;
                }
                k++;
            }
            arrayList.add(res);
        }
        int max = 0;
        for(int i =0;i<arrayList.size();i++){
            if(arrayList.get(i)>max){
                max = arrayList.get(i);
            }
        }
        return max;
    }