The plain recursion countPaths(r, c) = countPaths(r - 1, c) + countPaths(r, c - 1) is correct, but every leaf call contributes exactly 1 to the answer, so the number of leaf calls is the answer itself. On an 18 x 18 grid that is 2,333,606,220 leaf calls to compute 324 distinct cells. Memoising the recursion fixes it and ends up filling the same table. Tabulation fills it directly and skips the call stack. Incidentally that same number no longer fits in a 32-bit Int, which is why path-counting problems usually cap the grid or ask for the count modulo a prime.