Modify string by inserting characters such that every K | Function to replace all ' ? ' characters in a string such that the given conditions are satisfied ; Traverse the string to Map the characters with respective positions ; Traverse the string again and replace all unknown characters ; If i % k is not found in the Map M , then return - 1 ; Update S [ i ] ; Print the string S ; Driver Code
def fillString ( s , k ) : NEW_LINE INDENT mp = { } NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] != ' ? ' ) : NEW_LINE INDENT mp [ i % k ] = s [ i ] NEW_LINE DEDENT DEDENT s = list ( s ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( ( i % k ) not in mp ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE return NEW_LINE DEDENT s [ i ] = mp [ i % k ] NEW_LINE DEDENT s = ' ' . join ( s ) NEW_LINE print ( s ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " ? ? ? ? abcd " NEW_LINE K = 4 NEW_LINE fillString ( S , K ) NEW_LINE DEDENT