Reported October 2024
TikToktwo pointers

Find Max Squad Size

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

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

TikTok's October OA included a max squad size problem that looks like a simple array optimization question but hits on a constraint you'll miss on the first pass. You're given candidate qualifications or skill levels, and you need to find the largest group where some condition holds. The trap is assuming the condition is global when it's actually pairwise or range-based. StealthCoder will catch the edge case logic when you're under pressure and brain-locked on the first approach.

Pattern and pitfall

This problem is a filtering or greedy pattern dressed up in domain language. The core move is to sort the array and then apply a two-pointer or sliding-window check. The condition for a valid squad is usually something like 'the difference between max and min member skill is at most X' or 'any two members' scores differ by no more than a threshold.' Once sorted, the span of any valid subarray is contiguous, so you iterate and shrink or expand a window. The common mistake is iterating naively over all pairs, which tanks performance. The insight is that if a range [i, j] is valid, extending it by adding j+1 is a one-check operation, not a full re-scan. StealthCoder provides the exact condition check in real time if you're blocked on reading the problem's phrasing.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Find Max Squad Size 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

TikTok reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Max Squad Size FAQ

Is this a sliding window or two pointers problem?+

Both work. Two pointers is cleaner: sort, then use left and right indices, move left when the condition breaks. Sliding window also works if you expand right and contract left. Either way, you iterate the sorted array once, so O(n log n) time.

What's the condition that makes a squad valid?+

The problem statement will specify a constraint like 'max difference between any two members is at most K' or 'all members within a skill band.' Once you know it, sort the array and check only the span between the smallest and largest in each candidate range.

Why does sorting work for finding the max squad?+

Sorting lets you check a contiguous range of the sorted array. Any valid squad in the original array becomes a contiguous window in the sorted one. So you don't need to check all 2^n subsets, just O(n) windows.

What's the edge case everyone hits?+

Not verifying that the condition actually holds for your candidate range. Some people extract a window but forget to confirm the min-max span is within the limit. Always re-check before updating your max.

Is there a greedy trick to avoid checking all windows?+

Yes. Once a window [i, j] fails, there's no point checking [i, j+1] because you know the max-min span only grows. Shrink from the left instead. This is two pointers in action and keeps you O(n) after sorting.

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

OA at TikTok?
Invisible during screen share
Get it