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.
Flatland Space Stations
Flatland Space Stations
Sort by
recency
|
927 Discussions
|
Please Login in order to post a comment
Here is my easy c++ solution, you can watch the explanation here : https://youtu.be/k2pd5_9mseI
This algorithm is actually O(Nlog(N)) because of the sorting, we can make it O(N) by using a counting sort since we know what the maximum element of our array will be. you will have to replace the line
with this
And add this sort function in your editor
def flatlandSpaceStations(n, c): c.sort() end_max = max(c[0], n-1-c[-1]) in_max = max(c[i]-c[i-1] for i in range(1, len(c))) if len(c)!=1 else 0 return max(end_max, in_max//2)