Form Balanced 5v5 Matches From a Ranked Queue
Last updated: November 29, 2026
Quick Overview
Given queued players with matchmaking ratings and a maximum rating spread, form as many 10-player matches as possible where the spread inside each match is within tolerance, then split each match into two teams with close total rating.
Tencent
November 29, 20260
0
0 solved
Given queued players with matchmaking ratings and a maximum rating spread, form as many 10-player matches as possible where the spread inside each match is within tolerance, then split each match into two teams with close total rating.
Tencent's MOBA titles such as Honor of Kings run 5v5 ranked queues at very high concurrency, so matchmaking is a natural onsite coding topic for game backend roles. The interviewer is looking for the sorted-window insight, a proof sketch that greedy is optimal, and a sensible team-balancing heuristic.
What the Interviewer Expects
- Recognises that an optimal match can always be taken as 10 consecutive players in sorted order
- Uses a greedy left-to-right scan and argues it maximises match count
- Balances teams with a snake draft or similar and explains its quality
- States complexity clearly
- Discusses what happens to players left in the queue
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you widen the tolerance for players who have waited a long time?
- How do you handle pre-made parties of 2 or 3 that must stay together?
- Can you find the exact minimum team difference, and what does that cost?
- How would you shard the queue across servers by region and rank tier?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of (player_id, mmr), a tolerance T, match size 10. Output: a list of matches, each as two teams of 5 player IDs. Every match must satisfy max(mmr) - min(mmr) <= T. Maximise the numbe...
High-Level Design
Sort by MMR. Claim: if a valid set of k matches exists, a valid set exists where each match is a block of 10 consecutive sorted players. Exchange argument: if a match skips a player who is inside ...