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
Poker Comparator Implementation
00:00
5 left

Poker Comparator Implementation

HardPython

Problem

For a rules-oriented utility similar to logic evaluated in Guidewire PolicyCenter, implement a comparator for two five-card poker hands. Return 1 if the first hand wins, -1 if the second hand wins, and 0 if they are tied.

Cards are strings such as "AS", "10H", or "7C". The rank is one of 2 through 10, J, Q, K, or A; the final character is the suit. Evaluate hands using standard poker rankings, from highest to lowest: straight flush, four of a kind, full house, flush, straight, three of a kind, two pairs, one pair, and high card. Apply standard tie-breakers within the same category. An ace may be low only in the straight A-2-3-4-5.

Formal Specification

Implement compare_hands(hand1, hand2), where each argument is a list of exactly five unique card strings. Return an integer in {-1, 0, 1}.

Constraints

  • Each hand contains exactly five unique card strings.
  • Ranks are 2 through 10, J, Q, K, or A.
  • A hand is evaluated using standard five-card poker rankings.
  • An ace is low only for the straight A-2-3-4-5.

Function Signature

def compare_hands(hand1, hand2):
Interviewer

Your question is Poker Comparator Implementation. 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.