The update order
transcript
Count how a text can spell a pattern. Use one row of cells. The loop direction decides the answer. Let us see why.
Going upwards, a changed cell feeds the next one. So one letter fills two positions. The answer is six. Going downwards, every cell reads old values. The answer is three.
The text has one letter a. The pattern needs two of them. So the answer must be zero.
Going upwards returns one, which is wrong. Going downwards returns zero, which is right.
The cells start at one, zero, zero for the pattern aa. Going upwards, the letter a fills cell one, then cell two. Going downwards, cell two reads cell one before it changes. It stays zero.
Update the cells from the end. So each cell reads old values only. Always test a tiny case like this one.
Update from the largest index. Then every letter counts once. Full breakdown in the lecture.