Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write Test Cases for Cards

HardPython00:00
Practice interviewer
In session
5 left
00:00

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

You need to log in / sign up to run or submit.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output