Measure a Shared Contiguous Array Block

Quick Overview

Measure a Shared Contiguous Array Block. Return the greatest length of a contiguous block occurring in both nums 1 and nums 2.

Measure a Shared Contiguous Array Block

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the greatest length of a contiguous block occurring in both nums 1 and nums 2. A subsequence with gaps does not qualify. ```cpp class Solution { public: int findLength(vector<int>& nums1, vector<int>& nums2); }; ``` ### Examples **Example 1:** ```text nums1 = [2,4,6,8], nums2 = [1,4,6,9] Output: 2 Explanation: [4,6] occurs contiguously in both arrays. ``` **Example 2:** ```text nums1 = [1,2], nums2 = [3,4] Output: 0 Explanation: They share no element. ``` ### Constraints - Each array has from 1 to 1000 entries. - Every entry belongs to [0,100]. ### Contract considerations Require contiguity in both arrays. ```hint Read the boundary condition What state records the shared block ending at a pair of indices? ``` ### Boundary reminders Require contiguity in both arrays.

Overview: Measure a Shared Contiguous Array Block. Return the greatest length of a contiguous block occurring in both nums 1 and nums 2.

Google logo
Google
Jul 1, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the greatest length of a contiguous block occurring in both nums 1 and nums 2. A subsequence with gaps does not qualify.

class Solution {
public:
    int findLength(vector<int>& nums1, vector<int>& nums2);
};

Examples

Example 1:

nums1 = [2,4,6,8], nums2 = [1,4,6,9]
Output: 2
Explanation: [4,6] occurs contiguously in both arrays.

Example 2:

nums1 = [1,2], nums2 = [3,4]
Output: 0
Explanation: They share no element.

Constraints

  • Each array has from 1 to 1000 entries.
  • Every entry belongs to [0,100].

Contract considerations

Require contiguity in both arrays.

Boundary reminders

Require contiguity in both arrays.