Substring Reverse Pattern | Function to print the required pattern ; Print the unmodified string ; Reverse the string ; Replace the first and last character by ' * ' then second and second last character and so on until the string has characters remaining ; Driver code
def printPattern ( s , n ) : NEW_LINE INDENT print ( ' ' . join ( s ) ) NEW_LINE i , j = 0 , n - 1 NEW_LINE while i < j : NEW_LINE INDENT s [ i ] , s [ j ] = s [ j ] , s [ i ] NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT i , j = 0 , n - 1 NEW_LINE while j - i > 1 : NEW_LINE INDENT s [ i ] , s [ j ] = ' * ' , ' * ' NEW_LINE print ( ' ' . join ( s ) ) NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " geeks " NEW_LINE n = len ( s ) NEW_LINE printPattern ( list ( s ) , n ) NEW_LINE DEDENT