Ask LC: DP Patterns: index in loop and when to use len?

When dp[i][j] the loop for i and j is written, the (initialization; condition; update) is written in various way.

for (int i = A.size() - 1; i >= 0; --i)
    for (int j = i + 1; j  < A.size();  ++j)

Also, instead of using dp[i][j], length is used in some way for eg. dp[i][i+len].

for (int d = 1; d < n; d++)
            for (int i = 0; i < n - d; i++)
                dp[i][i + d] = max(p[i] - dp[i + 1][i + d], p[i + d] - dp[i][i + d - 1]);

Can the community enlighten us when to use which so that we spend less time thinking about that during the interview? Has anyone made any type of notes on this doubt?

Comments (1)