Coding Interview Prep: The Tournament Winner Problem

Moeedlodhi
3 min readNov 14, 2023

Another Day, Another Dollar. I mean Problem.

Let’s get started. This problem is used to determine the “winner” of a tournament.

Problem Statement:

In a competitive algorithms tournament, teams of programmers engage in round-robin matches, facing off against each other to solve algorithmic problems. Each match has a designated home team and away team, with a clear winner and loser, earning 3 points for a win and 0 points for a loss. The team with the highest total points at the end of all matches is declared the tournament winner.

Your task is to create a function that determines the tournament winner based on the provided arrays: “competition” and “results.” The “competition” array contains pairs of teams that have competed against each other (1 for the home team, 0 for the away team),

[homeTeam, awayTeam]

while the “results” array indicates the winner of each corresponding competition. It is guaranteed that only one team will emerge as the tournament winner, and each team competes against all others exactly once. The tournament will always involve at least two teams.

Sample Input:

 competitions = [
["HTML", "C#"],
["C#", "Python"],
["Python", "HTML"],
]

results = [0, 0, 1]

Sample Output:

"Python"
// C# beats HTML, Python Beats C#, and Python Beats HTML.
// HTML - 0 points
// C# - 3…

--

--