Find missing rank in a straight
Company: Pinduoduo
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Onsite
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.
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.
Input: (['9', 'T', 'J', 'Q'],)
Expected Output: '8'
Explanation: 9-K straight is missing K.
Input: (['T', 'J', 'Q', '0'],)
Expected Output: 'K'
Explanation: High-ace straight is missing K.
Hints
- Enumerate the valid five-rank straights and find the one containing all four input ranks.