Create an online match-making algorithm that receives players and dispatches a call to a game server when it finds players with ratings close enough to play against each other.
MatchMaking class
addPlayer(player id)- Game server information available
getRating(player1, player2)startGame(player1, player2)
Threshold to define“close enough”is a constant.
This problem asks you to design an online matchmaking system that pairs incoming players as soon as a suitable opponent is found. The key challenge is maintaining players waiting for a match and efficiently finding someone whose rating is within a fixed threshold, then calling the game server to start the game. A good solution typically uses a queue, balanced tree, or other ordered structure to support fast lookup and pairing in a streaming setting.