Print Concatenation of Zig | Function for zig - zag Concatenation ; Check is n is less or equal to 1 ; Iterate rowNum from 0 to n - 1 ; Iterate i till s . length ( ) - 1 ; Check is rowNum is 0 or n - 1 ; Driver Code
def zigZagConcat ( s , n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return s NEW_LINE DEDENT result = " " NEW_LINE for rowNum in range ( n ) : NEW_LINE INDENT i = rowNum NEW_LINE up = True NEW_LINE while ( i < len ( s ) ) : NEW_LINE INDENT result += s [ i ] NEW_LINE if ( rowNum == 0 or rowNum == n - 1 ) : NEW_LINE INDENT i += ( 2 * n - 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( up ) : NEW_LINE INDENT i += ( 2 * ( n - rowNum ) - 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT i += rowNum * 2 NEW_LINE DEDENT up ^= True NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT str = " GEEKSFORGEEKS " NEW_LINE n = 3 NEW_LINE print ( zigZagConcat ( str , n ) ) NEW_LINE