Find maximum distance between any city and station | Function to calculate the maximum distance between any city and its nearest station ; Initialize boolean list ; Assign True to cities containing station ;
def findMaxDistance ( numOfCities , station ) : NEW_LINE INDENT hasStation = [ False ] * numOfCities NEW_LINE for city in station : NEW_LINE INDENT hasStation [ city ] = True NEW_LINE DEDENT dist , maxDist = 0 , min ( station ) NEW_LINE for city in range ( numOfCities ) : NEW_LINE INDENT if hasStation [ city ] == True : NEW_LINE INDENT maxDist = max ( ( dist + 1 ) // 2 , maxDist ) NEW_LINE dist = 0 NEW_LINE DEDENT else : NEW_LINE INDENT dist += 1 NEW_LINE DEDENT DEDENT return max ( maxDist , dist ) NEW_LINE DEDENT / * Driver code * / NEW_LINE numOfCities = 6 NEW_LINE station = [ 3 , 1 ] NEW_LINE print ( " Max ▁ Distance : " , findMaxDistance ( numOfCities , station ) ) NEW_LINE