Flatland Space Stations
easy⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
Sample case — your program reads stdin and prints to stdout.
Flatland has n cities in a line (0 to n-1). Some cities have space stations. Find the maximum distance from any city to its nearest space station.
Example: n=5, stations at [0,4]. City 0: distance 0, City 1: min(1,3)=1, City 2: min(2,2)=2, City 3: min(3,1)=1, City 4: distance 0. Maximum is 2.
Input format
First line: n m (space-separated, m is number of stations). Second line: m space-separated integers (city indices with stations).
Output format
A single integer: the maximum distance to nearest space station.
Constraints
1 ≤ n ≤ 10⁵, 1 ≤ m ≤ n