human
Write me a code to rearrange characters in a string such that no two adjacent are same using hashing and the other steps required given the following:
Rearrange characters in a string such that no two adjacent are same using hashing | Function that returns true if it is possible to rearrange the characters of the String such that no two consecutive characters are same.
To store the frequency of each of the character.
To store the maximum frequency so far.
If possible.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to rearrange characters in a string such that no two adjacent are same using hashing and the other steps required.
 def isPossible ( Str ) :
	freq = dict ( )
	max_freq = 0
	for j in range ( len ( Str ) ) :
		freq [ Str [ j ] ] = freq . get ( Str [ j ] , 0 ) + 1
		if ( freq [ Str [ j ] ] > max_freq ) :
			max_freq = freq [ Str [ j ] ]
	if ( max_freq <= ( len ( Str ) - max_freq + 1 ) ) :
		return True
	return False
Str = " geeksforgeeks "
if ( isPossible ( Str ) ) :
	print ( " Yes " )
else :
	print ( " No " )