Square on a Winding Board
A board game has rows rows and cols columns of squares, numbered from 1 to rows * cols along a winding path. Square 1 is in the bottom-left corner. The numbers run from left to right along the bottom row, continue from right to left along the row above it, then from left to right along the next row up, and so on, switching direction on every row. Return the position of square number square as [row, col], where row 0 is the top row of the board and column 0 is the leftmost column.
Example 1
The bottom row (row 2) holds 1 to 4 from left to right and the middle row holds 5 to 8 from right to left, so 6 sits in row 1, column 2.
Example 2
The top row runs from left to right again with 9 to 12, so 12 is at its right end.
Constraints
1 <= rows, cols <= 101 <= square <= rows * cols
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.