Check if characters of a given string can be used to form any N equal strings | Function to check if the freq of any character is divisible by N ; Stores the frequency of characters ; If frequency of a character is not divisible by n ; If no character has frequency at least N ; Driver Code ; Function Call
function isSame ( str , n ) { var mp = { } ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( mp . hasOwnProperty ( str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) { mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] + 1 ; } else { mp [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = 1 ; } } for ( const [ key , value ] of Object . entries ( mp ) ) { if ( value >= n ) { return true ; } } return false ; } var str = " " ; var n = 4 ; if ( isSame ( str , n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }