Maximum Length of Repeated Subarray
MediumDynamic Programming2d dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given two integer arrays nums1 and nums2, return the length of the longest **contiguous** subarray that appears in both arrays with the same values in the same order.
If the arrays share no value at all, return 0.
An O(n * m) time solution is expected.
Examples
Input: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
Output: 3
[3,2,1] appears in both arrays.
Input: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
Output: 5
The arrays are identical.
Constraints
- 1 <= nums1.length, nums2.length <= 1000
- 0 <= nums1[i], nums2[i] <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.