Loop to find the minimum operations required such that frequency of every character is equal
for ( var i = 1 ; i <= 26 ; i ++ ) { if ( n % i === 0 ) { var x = n / i ; var y = 0 ; for ( var j = 0 ; j < i ; j ++ ) { y += Math . min ( freq [ j ] , x ) ; } answer = Math . min ( answer , n - y ) ; } } return answer ; }