Longest increasing sub | Function to find the LCS ; Loop to create frequency array ; Driver code
function findLCS ( arr , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) != 0 ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . set ( arr [ i ] , 1 ) ; } } return mp . size ; } let n = 3 ; let arr = [ 3 , 2 , 1 ] ; document . write ( findLCS ( arr , n ) ) ;