Boustrophedon Seat

Medium · rating 1350 · Matrix, Simulation

An r × c seating grid is numbered 1, 2, 3, … row by row, but every other row runs right-to-left (row 0 left-to-right, row 1 right-to-left, and so on). The first line has r and c. The second line has a 0-based row and col. Print the seat number at that position.

Constraints: 1 ≤ r, c ≤ 104

Related problems

Open Boustrophedon Seat in Code Arena →