Design card deck with shuffle and order
AppleSoftware Engineer · OnsiteLast updated
This question evaluates understanding of data modeling and API design for a deck abstraction, algorithmic handling of randomization and sorting, and the ability to analyze time and space complexity.
Design a playing-card deck library with two methods: shuffle() to return a uniformly random permutation of a standard 52-card deck, and order() to return cards sorted by rank then suit. Use the example ordering Clubs-3, Diamonds-3, Hearts-3, Spades-3, then continue rank 4 through Ace in the same suit order; explicitly define your suit and rank order and the data structures you will use; explain how you ensure an unbiased shuffle and analyze time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.