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
def power ( K , M ) : NEW_LINE INDENT res = 1 NEW_LINE while ( M > 0 ) : NEW_LINE INDENT if ( ( M & 1 ) == 1 ) : NEW_LINE INDENT res = ( res * K ) NEW_LINE DEDENT M = M >> 1 NEW_LINE K = ( K * K ) NEW_LINE DEDENT return res NEW_LINE DEDENT def cntWays ( arr , N , K ) : NEW_LINE INDENT cntways = 0 NEW_LINE M = 0 NEW_LINE st = set ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT st . add ( arr [ i ] ) NEW_LINE DEDENT M = len ( st ) NEW_LINE cntways = power ( K , M ) NEW_LINE return cntways NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE K = 2 NEW_LINE print ( cntWays ( arr , N , K ) ) NEW_LINE DEDENT