Maximum Strong Team Subarray

Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Microsoft OA. Under 2s to a working solution.
Founder's read

Microsoft reportedly put this one in front of candidates in July 2026, and the whole thing hinges on two running values, not a fancy data structure. If you have the OA in a day or two, relax. It's a dynamic programming problem wearing a hacker-team costume. At each index you pick from A or B, and the picks must be non-decreasing across a contiguous stretch. Track the best run ending at each position for each choice and you're done in one pass. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and surfaces the recurrence while you type.

The problem

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[]) → int

Examples
Example 1
team_a = [5, 2, 4, 1]
team_b = [3, 6, 2, 2]
return = 3
The optimal subarray covers positions 2 through 4. Choose team_a[1] = 2, team_b[2] = 2, and team_b[3] = 2.
Optimal choices in the exampleGroup or choicePosition 1Position 2Position 3Position 4
Group A5241
Group B3622
Selected skill-2 from A2 from B2 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^5
1 <= team_a[i], team_b[i] <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: keep two numbers per index, endA and endB. endA is the longest valid run ending at i where you picked team_a[i]. endB is the same for team_b[i]. Each starts at 1. Then check the previous index: if team_a[i-1] <= team_a[i], endA = max(endA, prevA + 1). If team_b[i-1] <= team_a[i], endA = max(endA, prevB + 1). Mirror that for endB. Answer is the max of everything seen. That's O(n) time and O(1) space, which matters with n up to 10^5. The common pitfall is only comparing within the same group, which misses the cross-group switch that makes example 1 work. Another one is resetting the run to zero instead of one. Because the subarray must be contiguous, a failed comparison just means that run restarts at 1. If the recurrence slips away under pressure, StealthCoder is the hedge during the live OA.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Maximum Strong Team Subarray cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Microsoft's OA.

Microsoft reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Strong Team Subarray FAQ

What's the trick in Maximum Strong Team Subarray?+

Track two values per index: the longest non-decreasing run ending with team_a[i] chosen, and the same for team_b[i]. Each one extends from either of the previous two runs if the previous skill is less than or equal to the current one. One pass, constant space.

How hard is this problem really?+

Medium. The idea is a small DP with four transitions per index. Most people who fail it either forget cross-group transitions or try brute force over all subarrays, which times out at 10^5 elements.

Why not just greedily pick the smaller value each position?+

Greedy picks can break a future run. Picking the smaller value helps the next step, but it might not be reachable from the previous pick. You need both options alive at every index, which is why you keep two run lengths instead of one.

What's the time complexity I should aim for?+

O(n) time and O(1) extra space. With n up to 10^5, anything quadratic will fail. You only need the previous index's two values, so no full DP table is required.

How do I prepare for this in 48 hours?+

Write the two-state recurrence by hand on example 1 until it's automatic. Then code it and test edge cases: length 1, all equal values, strictly decreasing arrays, and runs that only work by switching groups. That's enough for this problem type.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Microsoft.

OA at Microsoft?
Invisible during screen share
Get it