Most Frequent Training Partner Pair
A sports academy records the players attending each practice session. Each session is represented by a comma-separated string of player IDs.
Two players form a training pair when they attend the same session. Return the pair that appears together in the greatest number of sessions.
Method
List<String> findMostFrequentTrainingPair( List<String> practiceSessions )
practiceSessions contains the player IDs for every practice session.
- Player IDs within a session are separated by commas.
- Return the two player IDs forming the most frequent training pair.
Rules
- Generate every possible pair of players from each practice session.
- A session containing exactly two players generates one pair.
- A pair is unordered. Players
P01 and P03 form the same pair as P03 and P01.
- Each pair is counted at most once per session.
- Return the smaller player ID first.
- If multiple pairs have the same highest frequency, return the lexicographically smallest pair.
- No parameter value will be
null.
Constraints
1 <= practiceSessions.size() <= 50
- Every session contains between
2 and 50 player IDs.
- Every player ID contains between
1 and 20 uppercase English letters or digits.
- Player IDs are distinct within the same session.
- Player IDs are separated by single commas without spaces.
Examples
Example 1
findMostFrequentTrainingPair( practiceSessions = List.of( "T05,T02,T09", "T02,T05", "T07,T02,T05", "T09,T07" ) )
Output: List.of("T02","T05")
Players T02 and T05 attended three sessions together, more than any other pair.
Example 2
findMostFrequentTrainingPair( practiceSessions = List.of( "A04,A01", "A02,A03" ) )
Output: List.of("A01","A04")
Both pairs appear once. The pair containing A01 is lexicographically smaller.
Example 3
findMostFrequentTrainingPair( practiceSessions = List.of( "M03,M01,M02", "M01,M03", "M04,M02" ) )
Output: List.of("M01","M03")
Players M01 and M03 attended two sessions together. Every other pair appears only once.