Array ( [0] => [1] => questions [2] => Strings [3] => Zig-Zag-concatenation.-- )
Given a string N and value k. You have to convert the given string into k rows continuously and apply zig zag fashion on those k rows and combine those k rows.
First line contains the string N. Next line contains the value K.
Print the string with zig zag fashion.
abcdefgh 2
acegbdfh
coding 2
cdnoig
educate 3
ecedaut
Login to see Discussion
step-i) create a empty string answer
step-ii) assign 0 to n
step-iii) assign i to j
step-iv) append character at j in string to answer and increment j by N values
step-v) repeat step iv till j is less than length of string
step-vi) increment i by one value
step-vii)repeat steps iii to vi till i is less than N
step-viii) return answer
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution