Count of distinct possible strings after performing given operations | Function that prints the number of different strings that can be formed ; Computing the length of the given string ; Base case ; Traverse the given string ; If two consecutive 1 ' s ▁ ▁ or ▁ 2' s are present ; Otherwise take the previous value ; Driver Code
function differentStrings ( s ) { var n = s . length ; var dp = Array ( n + 1 ) ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] && ( s [ i ] == ' ' s [ i ] == ' ' ) ) dp [ i + 1 ] = dp [ i ] + dp [ i - 1 ] ; else dp [ i + 1 ] = dp [ i ] ; } document . write ( dp [ n ] + " " ) ; } var S = " " ; differentStrings ( S ) ;