private int traverse(int[][] grid, int row, int col, int totalCol) {
        int loc = row * totalCol + col;
        Integer cachedSum = cache.get(loc);

        if (cachedSum != null) {
            return cachedSum;
        } else {
            int cell = grid[row][col];

            if (row == grid.length - 1 && col == totalCol - 1) {
                return cell;
            } else {
                int sum = cell, sum1 = -1, sum2 = -1;

                if (row < grid.length - 1) {
                    sum1 = traverse(grid, row + 1, col, totalCol);
                }
                if (col < totalCol - 1) {
                    sum2 = traverse(grid, row, col + 1, totalCol);
                }

                if (sum1 != -1 && sum2 != -1) {
                    sum += Math.min(sum1, sum2);
                } else if (sum1 == -1) {
                    sum += sum2;
                } else if (sum2 == -1) {
                    sum += sum1;
                }

                cache.put(loc, sum);
                return sum;
            }
        }
    }