Longest sub | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxLen ( int * arr , int n ) { int min_val = * min_element ( arr , arr + n ) ; int freq = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == min_val ) freq ++ ; } return freq ; } int main ( ) { int arr [ ] = { 1 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << maxLen ( arr , n ) ; return 0 ; }