You can modify the input grid in-place to save space. Or use a 1D (one-dimensional) array since you only need the previous row. Fill left-to-right, top-to-bottom. The order matters because each cell depends on cells above and to the left. Time: , Space: if modifying in-place, with a rolling array. The code directly follows the recurrence relation. Trace through a small example by hand to see how each value is computed.
Time complexity: .
Space complexity: .