A cyber security firm is building a team of hackers to take down a network of cybercriminals. The skill level of the ith hacker of team A is team_a[i]
and of team B is team_b[i]
. A team is considered strong for each index i a hacker is selected either from team A or team B, and the skill levels of the selected team are non-decreasing.
Given two arrays team_a
and team_b
of n
integers each, choose two indices i
and j
such that the subarrays [team_a[i]
, team_a[i + 1]
, ... team_a[j]
] and [team_b[i]
, team_b[i + 1]
, ... team_b[j]
] can form a strong team. Find the maximum possible value of (j - i + 1)
i.e. the length of the chosen subarray.
Function Description
Complete the function getMaxSubarrayLen
in the editor.
getMaxSubarrayLen
has the following parameters:
int team_a[n]
: skill levels of team Aint team_b[n]
: skill levels of team B
Returns
int: the maximum subarray length that can be chosen to form a strong team
Example 1:

Input: team_a = [5, 2, 4], team_b = [3, 6, 2]
Output: 3
Explanation:As shown in the above image ๐
Example 2:
Input: team_a = [9, 7], team_b = [10, 8]
Output: 1
Explanation:Only a subarray of length 1 can be selected as [9, 8], [10, 7], etc. are all decreasing.
Example 3:
Input: team_a = [2, 3, 7], team_b = [4, 2, 6]
Output: 3
Explanation:The optimal selection is to choose the entire arrays and create the team [2, 2, 3] or [2, 2, 6]
- 1 <= n <= 105
- 1 <= team_a[i], team_b[i] <= 109
input:
output: