Count N | Function to count N - length strings consisting of vowels only sorted lexicographically ; Stores count of strings consisting of vowels sorted lexicographically of all possible lengths ; Initialize DP [ 1 ] [ 1 ] ; Traverse the matrix row - wise ; Base Case ; Return the result ; Driver Code ; Function Call
function findNumberOfStrings ( n ) { let DP = new Array ( n + 1 ) ; for ( var i = 0 ; i < DP . length ; i ++ ) { DP [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < DP . length ; i ++ ) { for ( var j = 0 ; j < DP . length ; j ++ ) { DP [ i ] [ j ] = 0 ; } } DP [ 1 ] [ 1 ] = 1 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { for ( let j = 1 ; j < 6 ; j ++ ) { if ( i == 1 ) { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + 1 ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + DP [ i - 1 ] [ j ] ; } } } return DP [ n ] [ 5 ] ; } let N = 2 ; document . write ( findNumberOfStrings ( N ) ) ;