This question evaluates object-oriented design skills, understanding of randomness and probability in algorithms, and analysis of time/space complexity for data structures and operations.
Design an in-memory model of a standard 52-card deck.
Card
(rank and suit)
Deck
(a collection of cards)
Deck
must support:
shuffle()
— randomizes the order of the remaining cards.
draw()
— removes and returns one card from the deck.
shuffle()
, every permutation of the remaining cards should be equally likely (i.e., an unbiased shuffle).
draw()
should return each remaining card with equal probability at that moment.
draw()
is called on an empty deck.
shuffle()
and
draw()
.
Random
).