Modify a string by circularly shifting each character to the right by respective frequencies | Function to replace the characters by its frequency of character in it ; Stores frequencies of characters in the string S ; Traverse the string S ; Increment the frequency of each character by 1 ; Traverse the string S ; Find the frequency of the current character ; Update the character ; Print the resultant string ; Driver Code
def addFrequencyToCharacter ( S ) : NEW_LINE INDENT frequency = [ 0 for i in range ( 26 ) ] NEW_LINE N = len ( S ) NEW_LINE S = list ( S ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT frequency [ ord ( S [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT add = frequency [ ord ( S [ i ] ) - ord ( ' a ' ) ] % 26 NEW_LINE if ord ( S [ i ] ) + add <= ord ( ' z ' ) : NEW_LINE INDENT S [ i ] = chr ( ord ( S [ i ] ) + add ) NEW_LINE DEDENT else : NEW_LINE INDENT add = ord ( S [ i ] ) + add - ord ( ' z ' ) NEW_LINE S [ i ] = chr ( ord ( ' a ' ) + add - 1 ) NEW_LINE DEDENT DEDENT s = " " NEW_LINE print ( s . join ( S ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " geeksforgeeks " NEW_LINE addFrequencyToCharacter ( S ) NEW_LINE DEDENT