Find the sum of the diagonal elements of the given N X N spiral matrix | Function to return the sum of both the diagonal elements of the required matrix ; Array to store sum of diagonal elements ; Base cases ; Computing the value of dp ; Driver code
< ? php function findSum ( $ n ) { $ dp = array ( ) ; $ dp [ 1 ] = 1 ; $ dp [ 0 ] = 0 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) { $ dp [ $ i ] = ( 4 * ( $ i * $ i ) ) - 6 * ( $ i - 1 ) + $ dp [ $ i - 2 ] ; } return $ dp [ $ n ] ; } $ n = 4 ; echo findSum ( $ n ) ; ? >