Problem · Array
Maximum Strong Team Subarray
Learn this problemProblem statement
A cybersecurity firm is building a team of hackers from two groups, A and B. The skill level of the hacker at position i in group A is team_a[i], and the corresponding skill level in group B is team_b[i].
A team is considered strong when it is formed from a contiguous range of positions and satisfies both of the following rules:
- At every position in the range, select exactly one hacker from either group A or group B.
- The selected skill levels are in non-decreasing order.
Given two integer arrays team_a and team_b of equal length, return the maximum possible length of a contiguous subarray that can form a strong team.
Function
getMaxSubarrayLen(team_a: int[], team_b: int[]) → intExamples
Example 1
team_a = [5, 2, 4, 1]team_b = [3, 6, 2, 2]return = 3The optimal subarray covers positions 2 through 4. Choose team_a[1] = 2, team_b[2] = 2, and team_b[3] = 2.
| Group or choice | Position 1 | Position 2 | Position 3 | Position 4 |
|---|---|---|---|---|
| Group A | 5 | 2 | 4 | 1 |
| Group B | 3 | 6 | 2 | 2 |
| Selected skill | - | 2 from A | 2 from B | 2 from B |
The selected skills are [2, 2, 2], which are non-decreasing, so the answer is 3.
Constraints
1 <= team_a.length = team_b.length <= 10^51 <= team_a[i], team_b[i] <= 10^9
More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026
- Escape Game - Maximize ScoreOA · Seen Jul 2026