Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Design a deck of cards with shuffle/draw
Design a Deck of Cards with Shuffle/Draw
Design an in-memory object-oriented model of a standard 52-card deck.
Requirements
- Create classes to represent at least:
Card(encapsulating rank and suit)Deck(a collection of cards)
- The
Deckclass must support the following operations:shuffle(): Randomizes the order of the remaining cards in the deck.draw(): Removes and returns a single card from the deck.
Correctness and Probability Constraints
- Unbiased Shuffle: After
shuffle()is called, every permutation of the remaining cards must be equally likely. - Equal Probability Draw: Each
draw()operation should return any of the currently remaining cards with equal probability.
Additional Considerations
- Clearly define the behavior when
draw()is called on an empty deck. - Analyze and discuss the time and space complexity for both
shuffle()anddraw()operations. - You may assume the availability of a good pseudo-random number generator (PRNG) for randomness (e.g.,
java.util.Randomor similar).
AI interview prep
Core dilemma
Ensuring truly unbiased randomness for shuffle and draw operations while maintaining efficient state management and adhering to robust object-oriented design principles, especially concerning the deck's evolving state.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a deck of cards with shuffle/draw
Design a Deck of Cards with Shuffle/Draw
Design an in-memory object-oriented model of a standard 52-card deck.
Requirements
- Create classes to represent at least:
Card(encapsulating rank and suit)Deck(a collection of cards)
- The
Deckclass must support the following operations:shuffle(): Randomizes the order of the remaining cards in the deck.draw(): Removes and returns a single card from the deck.
Correctness and Probability Constraints
- Unbiased Shuffle: After
shuffle()is called, every permutation of the remaining cards must be equally likely. - Equal Probability Draw: Each
draw()operation should return any of the currently remaining cards with equal probability.
Additional Considerations
- Clearly define the behavior when
draw()is called on an empty deck. - Analyze and discuss the time and space complexity for both
shuffle()anddraw()operations. - You may assume the availability of a good pseudo-random number generator (PRNG) for randomness (e.g.,
java.util.Randomor similar).