human
Write me a code to check if string can be rearranged so that every Odd length Substring is Palindrome and the other steps required given the following:
Check if string can be rearranged so that every Odd length Substring is Palindrome | Function to check is it possible to rearrange the string such that every odd length substring is palindrome.
Length of the string.
To count number of distinct character in string.
To count frequency of each character.
Inserting into set.
Incrementing the frequency.
All characters in the string are same.
There are more than 2 different character in string.
Currently there is 2 different character in string.
Get the frequencies of the characters that present in string.
Difference between their count is less than or equal to 1.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if string can be rearranged so that every Odd length Substring is Palindrome and the other steps required.
 def IsPossible ( s ) :
	n = len ( s ) ;
	count = set ( ) ;
	map = dict . fromkeys ( s , 0 ) ;
	for i in range ( n ) :
		count . add ( s [ i ] ) ;
		map [ s [ i ] ] += 1 ;
	if ( len ( count ) == 1 ) :
		return True ;
	if ( len ( count ) > 2 ) :
		return False ;
	j = 0
	it = list ( count ) [ j ] ;
	x = 0 ; y = 0 ;
	x = map [ it ] ;
	j += 1
	it = list ( count ) [ j ] ;
	y = map [ it ] ;
	if ( abs ( x - y ) <= 1 ) :
		return True ;
	return False ;
if __name__ == " _ _ main _ _ " :
	s = " aaaddad " ;
	if ( IsPossible ( s ) ) :
		print ( " YES " ) ;
	else :
		print ( " NO " ) ;