Longest sub | Java implementation of the approach ; 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
import java . util . Arrays ; class GFG { static int maxLen ( int [ ] arr , int n ) { int min_val = Arrays . stream ( arr ) . min ( ) . getAsInt ( ) ; int freq = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == min_val ) freq ++ ; } return freq ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 1 } ; int n = arr . length ; System . out . println ( maxLen ( arr , n ) ) ; } }