Count frequency of k in a matrix of size n where matrix ( i , j ) = i + j | PHP program to find the frequency of k in matrix where m ( i , j ) = i + j ; Driver Code
< ? php function find ( $ n , $ k ) { if ( $ n + 1 >= $ k ) return ( $ k - 1 ) ; else return ( 2 * $ n + 1 - $ k ) ; } $ n = 4 ; $ k = 7 ; $ freq = find ( $ n , $ k ) ; if ( $ freq < 0 ) echo " ▁ element ▁ not ▁ exist ▁ STRNEWLINE ▁ " ; else echo " ▁ Frequency ▁ of ▁ " , $ k , " ▁ is ▁ " , $ freq , " STRNEWLINE " ; ? >