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.
staticintflatlandSpaceStations(intn,int[]c){// Sort space station location in ascending orderArrays.sort(c);// Set max distance intially as the distance between city 0 to the first space stationintmaxDistance=c[0];// Calculate the max distance of the city between two space stationfor(inti=1;i<c.length;i++){maxDistance=Math.max(maxDistance,(c[i]-c[i-1])/2);}// Calculate the distance between the last n city to the last space stationmaxDistance=Math.max(maxDistance,(n-1)-c[c.length-1]);returnmaxDistance;}
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 8 solution: