Imagine you're a team captain dividing players into groups for a tournament! You have an array of n integers (where n is divisible by 3) and need to create exactly n/3 teams, each containing exactly 3 players.
Here's the challenge: within each team of 3, the difference between any two players' scores must not exceed k. This ensures balanced, competitive teams!
Your mission: Return a 2D array where each sub-array represents a valid team of 3 players. If it's impossible to form such balanced teams, return an empty array.
Example: With scores [1,3,3,2,7,3] and k=3, you could form teams like [[1,2,3],[3,3,7]] since within each team, no two scores differ by more than 3.
Input & Output
Constraints
- n == nums.length
- 1 โค n โค 105
- n is a multiple of 3
- 1 โค nums[i] โค 105
- 1 โค k โค 105