I was solving a question related to maximum sum of adjacent elements. I solved it recursively and tried to solve using tabulation as well but didn't succeeded in that. I went on internet and found a code which was working flawlessly but there i found a case in which we were tryin to accessing a negetive index inside a vector. As far as i know, it must had given me an error but it was running fine.
code for refrence:
int maximumNonAdjacentSum(vector<int> &nums){
int n = nums.size();
vector<int> table(n+1,0);
table[0] = nums[0];
for(int i=1;i<=n; i++){
table[i] = max(nums[i]+table[i-2],table[i-1]);
}
return table[n];
}