Array wave print

this code is working fine for sample input but not for test case code attached below

hi basant
check and dryrun for this input
3 3
4 5 6
7 8 9
7 5 3