Deal Cards Equally - Problem
You are given an array cards representing a deck of cards (as integers) and an integer k representing the number of players.
Deal the cards one by one in round-robin order to each player: the first card goes to Player 1, the second to Player 2, …, the k-th card to Player k, the (k+1)-th card back to Player 1, and so on.
Return a 2D array where the i-th sub-array contains the cards dealt to Player i+1, sorted in ascending order.
If there are leftover cards that don't fill a complete round, they are still dealt in order.
Input & Output
Example 1 — Even Deal
$
Input:
cards = [10,20,30,40,50,60], k = 3
›
Output:
[[10,40],[20,50],[30,60]]
💡 Note:
Player 1 gets cards at index 0,3 → [10,40]. Player 2 gets index 1,4 → [20,50]. Player 3 gets index 2,5 → [30,60].
Example 2 — Uneven Deal
$
Input:
cards = [5,3,8,1,7], k = 2
›
Output:
[[1,5,8],[3,7]]
💡 Note:
Player 1 gets index 0,2,4 → [5,8,7] → sorted [5,7,8]. Player 2 gets index 1,3 → [3,1] → sorted [1,3].
Example 3 — Single Player
$
Input:
cards = [9,2,6], k = 1
›
Output:
[[2,6,9]]
💡 Note:
Only one player gets all cards → sorted [2,6,9].
Constraints
- 1 ≤ cards.length ≤ 1000
- 1 ≤ cards[i] ≤ 10000
- 1 ≤ k ≤ cards.length
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code