Maximize the sum of Kth column of a Matrix | Function to maximize the Kth column sum ; Store all the elements of the resultant matrix of size N * N ; Store value of each elements of the matrix ; Fill all the columns < K ; Fill all the columns >= K ; Function to print the matrix ; Driver Code
def findMatrix ( N , K ) : NEW_LINE INDENT mat = [ [ 0 for i in range ( N ) ] for j in range ( N ) ] ; NEW_LINE element = 0 ; NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( 0 , K - 1 ) : NEW_LINE INDENT element += 1 ; NEW_LINE mat [ i ] [ j ] = element ; NEW_LINE DEDENT DEDENT for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( K - 1 , N ) : NEW_LINE INDENT element += 1 ; NEW_LINE mat [ i ] [ j ] = element ; NEW_LINE DEDENT DEDENT return mat ; NEW_LINE DEDENT def printMatrix ( mat , N ) : NEW_LINE INDENT for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( 0 , N ) : NEW_LINE INDENT print ( mat [ i ] [ j ] , end = " ▁ " ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 ; K = 2 ; NEW_LINE mat = findMatrix ( N , K ) ; NEW_LINE printMatrix ( mat , N ) ; NEW_LINE DEDENT