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
Write Test Cases for Cards
00:00
5 left

Write Test Cases for Cards

HardPython

Problem

Principal Financial Group's QA automation may receive a shuffled set of card identities representing a physical card-checking process. There are 103 face-down cards: 51 card identities appear exactly twice, and one identity appears exactly once. You may reveal only one card at a time.

Implement find_odd_card(cards) to return the unpaired card identity and the minimum number of flips required to guarantee finding it. Because an unseen card could still be the missing match, the algorithm must provide a worst-case guarantee rather than stopping when a candidate first appears.

Formal Specification

  • Input: cards, a list of integers containing 2k + 1 values. Every value appears exactly twice except one value, which appears once.
  • Output: A two-element list [odd_card, flips], where odd_card is the value appearing once and flips is the minimum number of cards that must be revealed in the worst case.
  • The standard deck configuration uses k = 51, so there are 103 cards.

Constraints

  • 1 <= k <= 10^6
  • len(cards) = 2k + 1
  • 0 <= cards[i] < 2^31
  • Exactly one value appears once
  • Every other value appears exactly twice

Function Signature

def find_odd_card(cards):
Interviewer

Your question is Write Test Cases for 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.