text: Longest subsequence where each character occurs at least k times | Javascript Program to find the subsequence with each character occurring at least k times in string s ; Function to find the subsequence ; Taking an extra array to keep record for character count in s ; Counting occurrences of all characters in str [ ] ; Printing characters with count >= k in same order as they appear in str . ; Driver code
code: var MAX_CHAR = 26 ; function findSubsequence ( str , k ) { var a = Array ( MAX_CHAR ) . fill ( 0 ) ; for ( var i = 0 ; i < str . length ; i ++ ) a [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < str . length ; i ++ ) if ( a [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] >= k ) document . write ( str [ i ] ) ; } var k = 2 ; findSubsequence ( " " , k ) ;