Wave print column wise

My code shows me run error on submission “https://ide.codingblocks.com/s/343365

for (int i = 0 ; i < arr[j].length ; i++)

in line 21

I again get the same error after fixing the line 21.

for input like
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

output is 1,5,9,13,14, …
your code starts with 1,2,3,4,8 …
just change the direction

My code is perfectly working in my ide and give me a correct answer, but on submission, it shows me run time error.

refer to this