Hackerrank – Flatland Space Stations

Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.

Solution

Fist I sorted the Space station, because they are not always ordered. Then I found out how many cities are between each pair of space stations i and i+1:

    \[((i + 1) - i - 1)\]

Then I calculated the maximum distance for each city in between 2 space stations.

    \[ceil(towns / 2)\]

In the end I compared the maximum with the distances between first no-space-station city (index 0) and first space station and the last city (index n - 1) and last space station.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply

Your email address will not be published. Required fields are marked *