text: Count ways to construct array with even product from given array such that absolute difference of same indexed elements is at most 1 | C # program to implement the above approach ; 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 3 ^ N - 2 ^ X ; Driver Code
code: using System ; class GFG { static void cntWaysConsArray ( int [ ] A , int N ) { int total = 1 ; int oddArray = 1 ; for ( int i = 0 ; i < N ; i ++ ) { total = total * 3 ; if ( A [ i ] % 2 == 0 ) { oddArray *= 2 ; } } Console . WriteLine ( total - oddArray ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 4 } ; int N = A . Length ; cntWaysConsArray ( A , N ) ; } }