Katkat

Find missing rank in a straight

TemuSoftware Engineer · Onsite

Last updated

This question evaluates a candidate's ability to map and manipulate encoded card ranks, reason about consecutive sequences with Ace-as-low or Ace-as-high semantics, and identify a missing element within a constrained set.

You are given a list of 4 distinct characters representing card ranks from a 5-card straight (5 consecutive ranks) with exactly one rank missing.

Ranks come from the set {A,2,3,4,5,6,7,8,9,10,J,Q,K}. To keep each rank as a single character, the input uses this encoding:

  • '0' represents Ace (A).
  • '2'–'9' represent ranks 2–9.
  • 'T' represents 10.
  • 'J', 'Q', 'K' represent Jack/Queen/King.

Aces can be used as low in the straight A-2-3-4-5 (treat Ace as value 1 in this case). Otherwise Ace is high above King.

Return the missing rank using the same encoding (i.e., return '0' if the missing rank is Ace).

Example:

  • Input: ['3','4','5','6'] → missing is '2' (straight 2-3-4-5-6)
  • Input: ['0','2','3','5'] → missing is '4' (straight A-2-3-4-5)