Assign True to cities containing station
for ( $ city = 0 ; $ city < $ n ; $ city ++ ) { $ hasStation [ $ station [ $ city ] ] = true ; } $ dist = 0 ; $ maxDist = PHP_INT_MAX ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ maxDist = min ( $ station [ $ i ] , $ maxDist ) ; } for ( $ city = 0 ; $ city < $ numOfCities ; $ city ++ ) { if ( $ hasStation [ $ city ] == true ) { $ maxDist = max ( ( int ) ( ( $ dist + 1 ) / 2 ) , $ maxDist ) ; $ dist = 0 ; } else $ dist += 1 ; } return max ( $ maxDist , $ dist ) ; }