Determine Straight Flush
Problem Description
Implement a function that determines whether a given set of poker cards contains a straight flush.
Input
You will receive a list of unique playing cards. Each card is represented by:
- A rank: one of
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A - A suit: one of
Spades, Hearts, Diamonds, Clubs
Definition of a Straight Flush
A straight flush is defined as a set of 5 cards that satisfy both of the following conditions:
- All five cards share the same suit.
- The five cards have consecutive ranks.
Assumptions
- The rank
A(Ace) can be used in two ways:- As a low card in the sequence
A-2-3-4-5. - As a high card in the sequence
10-J-Q-K-A.
- As a low card in the sequence
- The input list of cards will not contain any duplicate cards.
Output
The function should return true if at least one straight flush can be formed from the given cards, and false otherwise.
Examples
-
Input:
[(10, Hearts), (J, Hearts), (Q, Hearts), (K, Hearts), (A, Hearts), (3, Clubs)] -
Output:
true -
Input:
[(2, Spades), (3, Spades), (4, Spades), (5, Spades), (7, Spades)] -
Output:
false
AI interview prep
Core dilemma
The central engineering conflict here is ensuring absolute correctness and handling all specified edge cases (especially the dual nature of Ace) with optimal time and space complexity, while maintaining highly readable and maintainable code for a seemingly simple problem. It's about demonstrating mastery of fundamentals under scrutiny.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Determine Straight Flush
Problem Description
Implement a function that determines whether a given set of poker cards contains a straight flush.
Input
You will receive a list of unique playing cards. Each card is represented by:
- A rank: one of
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A - A suit: one of
Spades, Hearts, Diamonds, Clubs
Definition of a Straight Flush
A straight flush is defined as a set of 5 cards that satisfy both of the following conditions:
- All five cards share the same suit.
- The five cards have consecutive ranks.
Assumptions
- The rank
A(Ace) can be used in two ways:- As a low card in the sequence
A-2-3-4-5. - As a high card in the sequence
10-J-Q-K-A.
- As a low card in the sequence
- The input list of cards will not contain any duplicate cards.
Output
The function should return true if at least one straight flush can be formed from the given cards, and false otherwise.
Examples
-
Input:
[(10, Hearts), (J, Hearts), (Q, Hearts), (K, Hearts), (A, Hearts), (3, Clubs)] -
Output:
true -
Input:
[(2, Spades), (3, Spades), (4, Spades), (5, Spades), (7, Spades)] -
Output:
false