Count ways to split array into K non | Function to get the value of pow ( K , M ) ; Stores value of pow ( K , M ) ; Calculate value of pow ( K , N ) ; If N is odd , update res ; Update M to M / 2 ; Update K ; Function to print total ways to split the array that satisfies the given condition ; Stores total ways that satisfies the given condition ; Stores count of distinct elements in the given arr ; Store distinct elements of the given array ; Traverse the given array ; Insert current element into set st . ; Update M ; Update cntways ; Driver Code
function power ( K , M ) { var res = 1 ; while ( M > 0 ) { if ( ( M & 1 ) == 1 ) { res = ( res * K ) ; } M = M >> 1 ; K = ( K * K ) ; } return res ; } function cntWays ( arr , N , K ) { var cntways = 0 ; var M = 0 ; var st = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) { st . add ( arr [ i ] ) ; } M = st . size ; cntways = power ( K , M ) ; return cntways ; } var arr = [ 2 , 3 ] ; var N = arr . length ; var K = 2 ; document . write ( cntWays ( arr , N , K ) ) ;