Python3 program for the above approach
def maxindex ( dist , n ) : NEW_LINE INDENT mi = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( dist [ i ] > dist [ mi ] ) : NEW_LINE INDENT mi = i NEW_LINE DEDENT DEDENT return mi NEW_LINE DEDENT def selectKcities ( n , weights , k ) : NEW_LINE INDENT dist = [ 0 ] * n NEW_LINE centers = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT dist [ i ] = 10 ** 9 NEW_LINE DEDENT DEDENT