Longest sub | Function to return the length of the largest subsequence with minimum possible LCM ; Minimum value from the array ; To store the frequency of the minimum element in the array ; If current element is equal to the minimum element ; Driver code
function maxLen ( arr , n ) { var min_val = arr . reduce ( ( a , b ) => Math . min ( a , b ) ) var freq = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == min_val ) freq ++ ; } return freq ; } var arr = [ 1 , 3 , 1 ] ; var n = arr . length ; document . write ( maxLen ( arr , n ) ) ;