← 返回 apple 的题目列表Deck Shuffle and Draw OOD
类型:qbank
Design `Card` and `Deck` classes that support shuffle and draw with correct probabilities. The prompt is OOD-shaped but the algorithmic core is random sampling without replacement.
Examples
Example 1:
Input: ["Deck", "order"] [[], []]
Output: [null, ["2C","2D","2H","2S","3C","3D","3H","3S","4C","4D","4H","4S","5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S","8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S","JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS","AC","AD","AH","AS"]]
Explanation:
A fresh deck has all 52 cards, and order() returns the canonical sorted snapshot.
Example 2:
Input: ["Deck", "draw", "draw", "size", "order"] [[], [], [], [], []]
Output: [null, "2C", "2D", 50, ["2H","2S","3C","3D","3H","3S","4C","4D","4H","4S","5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S","8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S","JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS","AC","AD","AH","AS"]]
Explanation:
Fresh deck starts in canonical order, so the first two draws return 2C then 2D. The remaining 50 cards appear in sorted order.
Example 3:
Input: ["Deck", "shuffle", "order", "size"] [[], [], [], []]
Output: [null, null, ["2C","2D","2H","2S","3C","3D","3H","3S","4C","4D","4H","4S","5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S","8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S","JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS","AC","AD","AH","AS"], 52]
Explanation:
shuffle() permutes internal order but does not add/lose cards, so order() still produces the full 52-card canonical list.
Constraints
Always exactly 52 distinct cards at initialization
At most 1000 total method calls per test
order() does not mutate draw order