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.
Nice approach, but when I tried it I got timeout issues in Test #15 (C#). After all we still have to check if current city is in the stations array to reset chain counter. My solution (ofc not perfect) took about 770ms on my PC to calculate the result. And test #15 always gave me timeout error (although answer on my PC was correct).
So I tried another approach.
There are 3 possible cases for max distance:
From left outermost city to first station (just lowest value of stations array);
From right outermost city to last station (n - 1 - (max value of stations array));
From city somewhere in the middle between 2 stations;
All we have to do is to sort stations, find max distance between 2 stations, divide it by 2 to closest lowest integer and compare this distance with left distance and right distance. Max value will be result.
Calculation time for test #15 dropped to ~1ms on my PC. All tests passed successfully.
Flatland Space Stations
You are viewing a single comment's thread. Return to all comments →
Nice approach, but when I tried it I got timeout issues in Test #15 (C#). After all we still have to check if current city is in the stations array to reset chain counter. My solution (ofc not perfect) took about 770ms on my PC to calculate the result. And test #15 always gave me timeout error (although answer on my PC was correct).
So I tried another approach.
There are 3 possible cases for max distance:
All we have to do is to sort stations, find max distance between 2 stations, divide it by 2 to closest lowest integer and compare this distance with left distance and right distance. Max value will be result.
Calculation time for test #15 dropped to ~1ms on my PC. All tests passed successfully.