Let me explain why, after telling you about the number of robot paths, I suddenly got sentimental and wrote about Evgeniy Pankrat'ev.

In Problem 62, the robot teleports to the top-left cell, so there is only one possible path to reach it.

Illustration for “Calculating a row of Pascal's triangle in linear time: Part 1” (1 of 3)

When the robot can move only horizontally, there is only one way to visit every cell in the top row. Similarly, there is only one way to reach each cell in the leftmost column.

Illustration for “Calculating a row of Pascal's triangle in linear time: Part 1” (2 of 3)

The most interesting thing happens when the robot can reach a cell either by moving right or down. In that case, the number of ways to reach the cell is the sum of the numbers of ways to reach the cells above and to the left.

Illustration for “Calculating a row of Pascal's triangle in linear time: Part 1” (3 of 3)

You can see that dynamic programming solution looks like (and you suppose to write it like this on the interview)

fn path_number(h: usize, w: usize) -> i32 {
    assert!(h > 0 && w > 0);

    let mut c = vec![vec![0; w]; h];

    c[0][0] = 1; // the robot starts at the top-left cell

    for q in 1..w {
        c[0][q] = 1;
    }

    for p in 1..h {
        c[p][0] = 1;
    }

    for p in 1..h {
        for q in 1..w {
            c[p][q] = c[p - 1][q] + c[p][q - 1];
        }
    }

    c[h - 1][w - 1]
}

Next time - why this version works as well.