https://leetcode.com/problems/longest-arithmetic-sequence/
Why my code is getting wrong answer
see the dp[][] and please tell me why wrong ?
class Solution {
public:
int longestArithSeqLength(vector<int>& ar) {
int r = ar.size();
int c = *max_element(ar.begin(),ar.end());
int** dp = new int*[r+1];
for(int i=0;i<=r;i++){
dp[i] = new int[c+1];
for(int j=0;j<=c;j++){
dp[i][j] = 0;
}
}
//dp[0][ar[0]]=1;
for(int i=1;i<r;i++){
int k = i-1;
while(k>=0){
int val = abs(ar[i]-ar[k]);
if(val >=0){
dp[i][val] = 1+dp[i-1][val];
}
k--;
}
for(int j=0;j<=c;j++){
if(dp[i][j]==0){
dp[i][j] = dp[i-1][j];
}
}
}
int maximum =0;
for(int i=0;i<=c;i++){
if(maximum < dp[r-1][i]){
maximum = dp[r-1][i];
}
}
return maximum;
}
};