Count ways to build street under given constraints | Program to count ways ; Iterate from 2 to n ; driver program ; Count Ways
function countways ( n ) { let A = new Array ( n + 1 ) . fill ( 0 ) ; A [ 0 ] = 1 ; A [ 1 ] = 3 ; A [ 2 ] = 7 ; for ( let i = 2 ; i <= n ; i ++ ) { A [ i ] = 2 * A [ i - 1 ] + A [ i - 2 ] ; } return A [ n ] ; } let n = 5 ; document . write ( countways ( 5 ) )