HackerRank ‘Flatland Space Station’ Solution

Short Problem Definition:

Link

Complexity:

time complexity is O(N)

space complexity is O(N)

Execution:

This is a two pass algorithm. First, measure the distance to the last station on the left. And on the second pass measure the distance to the nearest station on the right. Pick the minimum of both values. Remember that the first and last position are not necessarily stations.