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 prlet the matrix ; Driver code
function findMatrix ( N , K ) { let mat = new Array ( N ) ; for ( var i = 0 ; i < mat . length ; i ++ ) { mat [ i ] = new Array ( 2 ) ; } let element = 1 ; for ( let i = 0 ; i < N ; ++ i ) { for ( let j = 0 ; j < K - 1 ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } for ( let i = 0 ; i < N ; ++ i ) { for ( let j = K - 1 ; j < N ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } return mat ; } function prletMatrix ( mat , N ) { for ( let i = 0 ; i < N ; ++ i ) { for ( let j = 0 ; j < N ; ++ j ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let N = 3 , K = 2 ; let mat = findMatrix ( N , K ) ; prletMatrix ( mat , N ) ;