Skip to content

Instantly share code, notes, and snippets.

@go-cristian
Created September 21, 2021 23:53
Show Gist options
  • Save go-cristian/76cacfc52bb8688a8b485b6cdfe1984e to your computer and use it in GitHub Desktop.
Save go-cristian/76cacfc52bb8688a8b485b6cdfe1984e to your computer and use it in GitHub Desktop.
function flatlandSpaceStations(n, c) {
let max = 0
if (n == c.length) {
return 0
}
for(let i = 0; i < n; i++){
var min = Math.abs(i - c[0])
for (let j=0; j < c.length; j++) {
const distance = Math.abs(i-c[j])
if (distance < min) {
min = distance
}
}
if(min > max){
max = min
}
}
return max
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment