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 ; Initialize max ; 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 ; Prlet the element having max frequency of digit k ; The digit whose max occurrence has to be found ; Given array ; Size of array ; Function Call
function countFreq ( N , K ) { let count = 0 ; while ( N > 0 ) { if ( N % 10 == K ) { count ++ ; } N = Math . floor ( N / 10 ) ; } return count ; } function findElementUtil ( arr , N , K ) { let c ; let max ; let ele = 0 ; max = 0 ; for ( let i = 0 ; i < N ; i ++ ) { c = countFreq ( arr [ i ] , K ) ; if ( c > max ) { max = c ; ele = arr [ i ] ; } } if ( max == 0 ) return - 1 ; else return ele ; } function findElement ( arr , N , K ) { let ele = findElementUtil ( arr , N , K ) ; if ( ele == - 1 ) document . write ( " " ) ; else document . write ( ele ) ; } let K = 3 ; let arr = [ 3 , 77 , 343 , 456 ] ; let N = arr . length ; findElement ( arr , K , N ) ;