human
Lexicographically largest string formed from the characters in range L and R | Function to return the lexicographically largest string.
hash array.
make 0 - based indexing.
iterate and count frequencies of character.
ans string.
iterate in frequency array.
add til all characters are added.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to lexicographically largest string formed from the characters in range L and R and the other steps required.
 def printLargestString ( s , l , r ) :
	freq = [ 0 ] * 26
	l -= 1
	r -= 1
	for i in range ( min ( l , r ) , max ( l , r ) + 1 ) :
		freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
	ans = " "
	for i in range ( 25 , - 1 , - 1 ) :
		while ( freq [ i ] ) :
			ans += chr ( ord ( ' a ' ) + i )
			freq [ i ] -= 1
	return ans
if __name__ == " _ _ main _ _ " :
	s = " striver "
	l = 3
	r = 5
	print ( printLargestString ( s , l , r ) )