Choose the Front Football Team
Learn this problemProblem statement
Two football teams, teamA and teamB, must stand in front and back rows for a photograph. Players may be reordered within their own team but may not switch teams. Sort each team's heights in nondecreasing order and left-align both rows in max(teamA.length, teamB.length) positions. Missing trailing positions are empty.
For every position occupied in both rows, the front player must be strictly shorter than the back player. Empty positions impose no comparison. Return "A" when only team A can stand in front, "B" when only team B can, "EITHER" when both arrangements work, and "IMPOSSIBLE" when neither works.
Function
chooseFrontTeam(teamA: int[], teamB: int[]) → StringExamples
Example 1
teamA = [5,8,6]teamB = [6,7,9]return = "A"After sorting, the aligned pairs are (5,6), (6,7), and (8,9), so team A can stand in front.
Example 2
teamA = [6,7]teamB = [5,8,9]return = "IMPOSSIBLE"Team A cannot be in front because 6 is not shorter than 5. Team B cannot be in front because 8 is not shorter than 7. The final position in team B is unpaired.
Example 3
teamA = []teamB = [4,5]return = "EITHER"No position is occupied by both teams, so neither possible front row blocks a back-row player.
Constraints
0 <= teamA.length, teamB.length <= 200000.1 <= teamA[i], teamB[i] <= 10^9.- Each team may be sorted independently, and an empty trailing position never blocks a player.