Hard Problemscountingcombinatoricsgrid

Count of AP Subsequences

Given an array of numbers, count the subsequences of length three or more whose elements form an arithmetic progression, meaning each chosen value after the first differs from the one before it by the same fixed amount.

Note. The natural table for this counts AP subsequences by the PAIR of positions their last two elements sit at, which is correct and agrees with brute force, but its answer is the total over every cell rather than any one cell's value. This page therefore states the problem without a traced table.

Do this lesson first: climbing stairs

The full breakdown and animated table for this problem are still being written. In the meantime, run the four questions on it yourself. That is the whole exercise.