O(n) of ZigZag conversion