"Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays." I was trying to solve this question on Leetcode.
This is the code I wrote:
int findLength(vector<int>& nums1, vector<int>& nums2) {
    int l1=nums1.size()+1;
    int l2= nums2.size()+1;
    int dp[1000][1000]={0};
    for(int i=l1-1; i>=0; i++){
        for(int j=l2-1; j>=0; j++){
            if(nums1.at(i)==nums2.at(j)){
                dp[i][j]=dp[i+1][j+1]+1;
                break;
            }
        }
    }
    int maxm=0;
    for(int i=0; i<l1; i++){
        for(int j=0; j<l2; j++){
            if(dp[i][j]>maxm){
                maxm=dp[i][j];                }
        }
    }
    return maxm;
}
But I got an error I cant understand:
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4) Blockquote
Blockquote
