Find missing rank in a straight
TemuSoftware Engineer · OnsiteLast 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'(straight2-3-4-5-6) - Input:
['0','2','3','5']→ missing is'4'(straightA-2-3-4-5)
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.