Count of distinct N | Python Program for the above approach ; Function to find the count of distinct odd integers with N digits using the given digits in the array arr [ ] ; Stores the factorial of a number Calculate the factorial of all numbers from 1 to N ; Stores the frequency of each digit ; Stores the final answer ; Loop to iterate over all values of Nth digit i and 1 st digit j ; If digit i does not exist in the given array move to next i ; Fixing i as Nth digit ; Stores the answer of a specific value of i and j ; If digit j does not exist move to the next j ; Fixing j as 1 st digit ; Calculate number of ways to arrange remaining N - 2 digits ; Including j back into the set of digits ; Including i back into the set of the digits ; Return Answer ; Driver Code ; Function Call
from array import * NEW_LINE from math import * NEW_LINE def countOddIntegers ( arr , N ) : NEW_LINE INDENT Fact = [ 0 ] * N NEW_LINE Fact [ 0 ] = 1 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT Fact [ i ] = i * Fact [ i - 1 ] NEW_LINE DEDENT freq = [ 0 ] * 10 NEW_LINE for i in range ( len ( freq ) ) : NEW_LINE INDENT freq [ i ] = 0 ; NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT freq [ arr [ i ] ] = freq [ arr [ i ] ] + 1 ; NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 1 , 10 , 2 ) : NEW_LINE INDENT if ( freq [ i ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT freq [ i ] = freq [ i ] - 1 ; NEW_LINE for j in range ( 1 , 10 , 1 ) : NEW_LINE INDENT cur_ans = 0 NEW_LINE if ( freq [ j ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT freq [ j ] = freq [ j ] - 1 ; NEW_LINE cur_ans = Fact [ N - 2 ] NEW_LINE for k in range ( 10 ) : NEW_LINE INDENT cur_ans = cur_ans / Fact [ freq [ k ] ] NEW_LINE DEDENT ans += cur_ans NEW_LINE freq [ j ] = freq [ j ] + 1 ; NEW_LINE DEDENT freq [ i ] = freq [ i ] + 1 ; NEW_LINE DEDENT return ceil ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 2 , 3 , 4 , 1 , 2 , 3 ] NEW_LINE N = len ( A ) NEW_LINE print ( countOddIntegers ( A , N ) ) NEW_LINE DEDENT