A sequence from 1 to N is written in a zigzag pattern on a given number R of rows .
For example, N = 12, R = 3. You should encode it as
And if N = 12, R = 4. You should encode it as
In the end, you should output this sequence in order like 1 5 9 2 4 6 8 10 12 3 7 11 .
seperated by space and end by space, no need to change line.
Two number N & R.
N is the length of sequence.
R is the numbers of row.
An encoded sequence in row-major order.