We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flatland Space Stations
You are viewing a single comment's thread. Return to all comments →
JAVA
static int flatlandSpaceStations(int n, int[] c) {