Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straight forward and very clear solution in Clear category for Zigzag Array by kkkkk
from typing import List
def create_zigzag(rows: int, cols: int, start: int = 1) -> List[List[int]]:
"""Return a 2-dimensional array with odd rows reversed."""
result_array = []
for row in range(rows):
if row % 2:
# Odd rows (actually even numbered rows since the index is
# zero-based) are to be reversed.
result_array.append([x for x in range(start+cols-1, start-1, -1)])
else:
result_array.append([x for x in range(start, start+cols)])
start += cols
return result_array
Aug. 28, 2019