Count ways to construct array with even product from given array such that absolute difference of same indexed elements is at most 1 | Function to find count the ways to construct an array , B such that abs ( A [ i ] - B [ i ] ) <= 1 and product of elements of B is even ; Stores count of arrays B such that abs ( A [ i ] - B [ i ] ) <= 1 ; Stores count of arrays B whose product of elements is not even ; Traverse the array ; Update total ; If A [ i ] is an even number ; Update oddArray ; Print var 3 ^ N - 2 ^ X ; Driver Code
function cntWaysConsArray ( A , N ) { var total = 1 ; var oddArray = 1 ; for ( i = 0 ; i < N ; i ++ ) { total = total * 3 ; if ( A [ i ] % 2 == 0 ) { oddArray *= 2 ; } } document . write ( total - oddArray ) ; } var A = [ 2 , 4 ] ; var N = A . length ; cntWaysConsArray ( A , N ) ;