β back to unit
Challenge
# sorting advanced
The Card Player's Sort
Card players don't bubble β they pick up cards one at a time and slide each into its right spot in the hand. π
You get a list of nums. Sort it the card player's way: for each value, shift bigger values right until you find its home. Print the result, comma-separated.
Example:
Input: nums = [5, 2, 9, 1, 5]
Output: 1,2,5,5,9
Sliding each drawn card left past bigger values into its spot: 5 stays, 2 slides in front of 5, 9 stays at the end, 1 slides all the way to the front, and the second 5 slides next to the first β building 1,2,5,5,9.
π‘ need a hint?
sort-card-players-sort.pyπ given lines are locked β write your code in between
loading...