Count frequency of k in a matrix of size n where matrix ( i , j ) = i + j | Javascript program to find the frequency of k in matrix where m ( i , j ) = i + j ; Driver Code
function find ( n , k ) { if ( n + 1 >= k ) return ( k - 1 ) ; else return ( 2 * n + 1 - k ) ; } var n = 4 , k = 7 ; var freq = find ( n , k ) ; if ( freq < 0 ) document . write ( " " ) ; else document . write ( " " + k + " " + freq + " " ) ;