human
What is a code to lexicographically largest subsequence such that every character occurs at least k times and the other steps required given the following:
Lexicographically largest subsequence such that every character occurs at least k times | Find lexicographically largest subsequence of s [ 0. . n - 1 ] such that every character appears at least k times . The result is filled in t [ ].
Starting from largest charter ' z ' to 'a.
Counting the frequency of the character.
If frequency is greater than k.
From the last point we leave.
check if string contain ch.
If yes , append to output string.
Update the last point ..
Driver Code"
Solution in Python:
assistant
#Here is code to lexicographically largest subsequence such that every character occurs at least k times and the other steps required.
 def subsequence ( s , t , n , k ) :
	last = 0
	cnt = 0
	new_last = 0
	size = 0
	string = ' zyxwvutsrqponmlkjihgfedcba '
'
	for ch in string :
		cnt = 0
		for i in range ( last , n ) :
			if s [ i ] == ch :
				cnt += 1
		if cnt >= k :
			for i in range ( last , n ) :
				if s [ i ] == ch :
					t [ size ] = ch
					new_last = i
					size += 1
			last = new_last
if __name__ == " _ _ main _ _ " :
	s = [ ' b ' , ' a ' , ' n ' , ' a ' , ' n ' , ' a ' ]
	n = len ( s )
	k = 2
	t = [ ' ' ] * n
	subsequence ( s , t , n - 1 , k )
	t = ' ' . join ( t )
	print ( t )