Maximum Length of Repeated Subarray

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

Example 1
Inputnums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
Output3
The repeated subarray with maximum length is [3, 2, 1].
Example 2
Inputnums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
Output5
The repeated subarray with maximum length is [0, 0, 0, 0, 0].

Constraints

  • 1 <= nums1.length, nums2.length <= 1000
  • 0 <= nums1[i], nums2[i] <= 100

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate