Your question is Best 5-Card Hand From N Cards. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
A Terra workflow validation utility receives a collection of unique playing cards and must identify the strongest possible five-card poker hand. Implement a function that returns the selected cards' original indices in ascending order.
Each card is a two-character string: a rank from 2 through 9, T, J, Q, K, or A, followed by a suit from C, D, H, or S. The input contains at least five cards and may be in any order.
Return the indices of the best five-card hand. Rank hands using standard poker categories, from strongest to weakest: straight flush, four of a kind, full house, flush, straight, three of a kind, two pair, one pair, and high card. Resolve ties using the standard rank tie-breakers. If multiple selections have exactly the same poker value, return the lexicographically smallest sorted index list.
def best_five_indices(cards):