• + 10 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:

    • 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.