Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays.

&nbsp;
Example 1:

Input: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
Output: 3
Explanation: The repeated subarray with maximum length is [3,2,1].


Example 2:

Input: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
Output: 5


&nbsp;
Constraints:


	1 &lt;= nums1.length, nums2.length &lt;= 1000
	0 &lt;= nums1[i], nums2[i] &lt;= 100


class Solution:
    def findLength(self, nums1: List[int], nums2: List[int]) -> int:
        dp = [[0]*(len(nums1)+ 1) for _ in range(len(nums2) + 1)]
        max_len = 0
        for row in range(len(nums2)):
            for col in range(len(nums1)):
                if nums2[row] == nums1[col]:
                    dp[row][col] = 1 + dp[row - 1][col - 1]
                    max_len = max(max_len,dp[row][col])
                else:
                    dp[row][col] = 0
        return max_len
    
class Solution {
    public int findLength(int[] nums1, int[] nums2) {
        int n=  nums1.length , m = nums2.length;
        int[][] dp = new int [n+1][m+1];
        // for(int [] d: dp)Arrays.fill(d,-1);
        int ans =0;
            for(int i =n-1;i>=0;i--){
                for(int j = m-1 ;j>=0;j--){
                    if(nums1[i]==nums2[j]){
                        dp[i][j] = dp[i+1][j+1]+1;
                        if(ans<dp[i][j])ans = dp[i][j];
                    }
                }
            } 
        return ans;
    }
}
class Solution {
public:
    int findLength(vector<int>& nums1, vector<int>& nums2) {
        
        
        int n1 = nums1.size();
        int n2 = nums2.size();

        //moving num2 on num1
        
        int ptr2 = 0;
        
        int cnt = 0;
        
        int largest  = INT_MIN;
        
        for(int i=0;i<n1;i++)
        {
            cnt = 0;
            for(int j=i,ptr2=0;j<n1 && ptr2<n2;j++,ptr2++)
            {
                if(nums1[j]==nums2[ptr2])
                {
                    cnt++;
                    
                }
                else
                {
                    cnt = 0;
                }
                largest = max(largest,cnt);
            }
        }
        
        //moving num1 on num2
        ptr2 = 0;
        cnt = 0;
        for(int i=0;i<n2;i++)
        {
            cnt = 0;
            for(int j=i,ptr2=0;j<n2 && ptr2<n1;j++,ptr2++)
            {
                if(nums2[j]==nums1[ptr2])
                {
                    cnt++;
                }
                else
                {
                    cnt = 0;
                }
                largest = max(largest,cnt);
            }
        }
        
        return largest;
        
    }
};
var findLength = function(nums1, nums2) {
    let dp = new Array(nums1.length+1).fill(0).map(
        () => new Array(nums2.length+1).fill(0)
    )
    let max = 0;
    for (let i = 0; i < nums1.length; i++) {
        for (let j = 0; j < nums2.length; j++) {
            if (nums1[i] != nums2[j]) {
                continue;
            }
            dp[i+1][j+1] = dp[i][j]+1;
            max = Math.max(max, dp[i+1][j+1]);
        }
    }

    return max;
};
Maximum Length of Repeated Subarray