Choose the Front Football Team
Updated
Problem statement
Two football teams, teamA and teamB, line up for a photograph. One team stands in the front row and the other stands in the back row. You may reorder players within their own team, but no player can switch teams.
Sort each team's heights from shortest to tallest. Then line up both rows from the left, using max(teamA.length, teamB.length) positions. If a team has fewer players, the last positions in its row stay empty.
At every position where both rows have a player, the front player must be strictly shorter than the back player. An empty position does not need any comparison. Return "A" if only team A can stand in front, "B" if only team B can, "EITHER" if both ways work, and "IMPOSSIBLE" if neither way works.
Function
chooseFrontTeam(teamA: int[], teamB: int[]) → StringExamples
Example 1
teamA = [5,8,6]teamB = [6,7,9]return = "A"After sorting, the pairs at each position are (5,6), (6,7), and (8,9), with team A first in each pair. Every team A player is shorter than the team B player behind, so team A can stand in front. Team B cannot, because its shortest player is not shorter than team A's shortest player. The answer is "A".
Example 2
teamA = [6,7]teamB = [5,8,9]return = "IMPOSSIBLE"Team A cannot be in front, because its first player, 6, is not shorter than team B's first player, 5. Team B cannot be in front, because its second player, 8, is not shorter than team A's second player, 7. Team B's last player has no one in the other row at that position. Neither way works, so the answer is "IMPOSSIBLE".
Example 3
teamA = []teamB = [4,5]return = "EITHER"Team A has no players, so no position has players in both rows. Nothing blocks either team from standing in front, so the answer is "EITHER".
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.
More Anduril interview questions
- Pacific Atlantic Water FlowPHONE SCREEN · Seen Aug 2026
- Maximum Visible DronesPHONE SCREEN · Seen Jun 2024
- Build a Sorted Circular Singly Linked ListPHONE SCREEN · Seen Feb 2024
- Sparse Vector Dot ProductPHONE SCREEN · Seen Apr 2021
- Add Word and Suffix SearchONSITE INTERVIEW · Seen Aug 2026
- Binary Tree Preorder TraversalONSITE INTERVIEW · Seen Aug 2026
- Operator-First Array CalculatorONSITE INTERVIEW · Seen Aug 2026
- Daily TemperaturesONSITE INTERVIEW · Seen Jun 2024
- Highlighted Context WindowsONSITE INTERVIEW · Seen Jun 2024
Similar questions at other companies
- Assign CookiesAmazon · PHONE SCREEN
- Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Remove the Fewest Magic BeansThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Minimize Range After Three ChangesDRW · PHONE SCREENDRW interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- IPOTekion · PHONE SCREENTekion interview questions
- Experiment Bucket Allocation and RebalancingPinterest · PHONE SCREENPinterest interview questions