Find missing rank in a straight
Company: Pinduoduo
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Onsite
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`)
Quick Answer: 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.
Given four distinct encoded ranks from a five-card straight, return the missing encoded rank.
Constraints
- Input ranks are distinct
- A valid unique straight exists for the tests
Examples
Input: (['3', '4', '5', '6'],)
Expected Output: '2'
Explanation: Straight 2-6 is missing 2.
Input: (['0', '2', '3', '5'],)
Expected Output: '4'
Explanation: Ace-low straight is missing 4.
Hints
- Enumerate the valid five-rank straights and find the one containing all four input ranks.