ZigZag conversion solvedwith O(1) memory and O(n + nRows^2) time