Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Best 5-Card Hand From N Cards
00:00
5 left

Best 5-Card Hand From N Cards

HardPython

Problem

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.

Formal Specification

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.

Constraints

  • 5 <= len(cards) <= 25
  • Each card is a two-character string with a valid rank and suit
  • All cards are unique
  • Aces can be high or low only when forming a straight
  • Return exactly five indices in ascending order

Function Signature

def best_five_indices(cards):
Interviewer

Your question is Best 5-Card Hand From N Cards. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.