Longest Arithmetic Subsequence — Solution & Editorial
dp[i][d] = longest AP ending at i with common difference d; for each pair (j, i) extend dp[j][ai−aj]. Store the per-index difference map.
Complexity: O(N2)
dp[i][d] = longest AP ending at i with common difference d; for each pair (j, i) extend dp[j][ai−aj]. Store the per-index difference map.
Complexity: O(N2)