Iterate for the first sub - array and store the maximum
for ( let i = 0 ; i < M ; i ++ ) { if ( m . has ( A [ i ] ) ) { m . set ( m . get ( A [ i ] ) , m . get ( A [ i ] ) + 1 ) ; } else { m . set ( A [ i ] , 1 ) ; } val = Math . max ( val , m . get ( A [ i ] ) ) ; }