Maximize count of Decreasing Subsequences from the given Array | Java program for rearrange array to generate maximum decreasing subsequences ; Function to count maximum subsequence ; Stores the frequency of array elements ; Stores maximum frequency ; Update frequency of A [ i ] ; Update maximum subsequences ; Print the result ; Driver Code
import java . util . HashMap ; import java . util . Map ; public class Main { public static void Maximum_subsequence ( int [ ] A , int N ) { HashMap < Integer , Integer > frequency = new HashMap < > ( ) ; int max_freq = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( frequency . containsKey ( A [ i ] ) ) { frequency . replace ( A [ i ] , frequency . get ( A [ i ] ) + 1 ) ; } else { frequency . put ( A [ i ] , 1 ) ; } } for ( Map . Entry it : frequency . entrySet ( ) ) { if ( ( int ) it . getValue ( ) > max_freq ) { max_freq = ( int ) it . getValue ( ) ; } } System . out . println ( max_freq ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 6 , 5 , 2 , 4 , 5 , 2 } ; int N = arr . length ; Maximum_subsequence ( arr , N ) ; } }