Find the array element having maximum frequency of the digit K | Function to find the count of digits , k in the given number n ; Stores count of occurrence of digit K in N ; Iterate over digits of N ; If current digit is k ; Update count ; Update N ; Utility function to find an array element having maximum frequency of digit k ; Stores frequency of digit K in arr [ i ] ; Stores maximum frequency of digit K in the array ; Stores an array element having maximum frequency of digit k ; Traverse the array ; Count the frequency of digit k in arr [ i ] ; Update max with maximum frequency found so far ; Update ele ; If there is no array element having digit k in it ; Function to find an array element having maximum frequency of digit k ; Stores an array element having maximum frequency of digit k ; If there is no element found having digit k in it ; Print element having max frequency of digit k ; Driver Code ; The digit whose max occurrence has to be found ; Given array ; Size of array ; Function Call
def countFreq ( N , K ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N > 0 ) : NEW_LINE INDENT if ( N % 10 == K ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT N = N // 10 NEW_LINE DEDENT return count NEW_LINE DEDENT def findElementUtil ( arr , N , K ) : NEW_LINE INDENT c = 0 NEW_LINE max = 0 NEW_LINE ele = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT c = countFreq ( arr [ i ] , K ) NEW_LINE if ( c > max ) : NEW_LINE INDENT max = c NEW_LINE ele = arr [ i ] NEW_LINE DEDENT DEDENT if ( max == 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return ele NEW_LINE DEDENT DEDENT def findElement ( arr , N , K ) : NEW_LINE INDENT ele = findElementUtil ( arr , N , K ) NEW_LINE if ( ele == - 1 ) : NEW_LINE INDENT print ( " - 1" , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ele ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 3 NEW_LINE arr = [ 3 , 77 , 343 , 456 ] NEW_LINE N = len ( arr ) NEW_LINE findElement ( arr , K , N ) NEW_LINE DEDENT