Four-Player Matching Card Game
Updated
Problem statement
Cards are encoded as rank-suit, where rank is an integer and suit is a nonempty uppercase token. deckOrder is the supplied deck from top to bottom.
- Deal
handSizecards to each of four players in round-robin order, then sort every hand by rank and suit. - Draw the next deck card as the current card.
- Players take turns
0,1,2,3. A player plays the first card in their sorted hand whose rank or suit matches the current card. That card becomes current. - If no card matches, draw the next deck card into the hand, sort the hand, and end the turn without immediately playing it.
- Return the first player whose hand becomes empty. If the draw pile is empty and a full round passes with no play, return
-1.
Function
matchingCardGameWinner(deckOrder: String[], handSize: int) → intExamples
Example 1
deckOrder = ["1-A","2-B","3-C","4-D","5-A"]handSize = 1return = 0Player 0 plays 1-A on 5-A and empties their hand.
Example 2
deckOrder = ["1-A","2-B","3-C","4-D","9-B","8-A"]handSize = 1return = 1Player 0 draws 8-A and ends the turn; player 1 then plays 2-B on 9-B.
Example 3
deckOrder = ["1-A","2-B","3-C","4-D","9-E"]handSize = 1return = -1No hand matches rank 9 or suit E, and no draw cards remain.
Constraints
1 <= handSizeand4*handSize+1 <= deckOrder.length <= 200000.- Every card matches
[1-9][0-9]*-[A-Z]+. - The deck order is fixed, so the same input always gives the same game. Duplicate card codes are allowed.
More Scale AI Onsite Interview questions
- Task Scheduler with DependenciesONSITE INTERVIEW · Seen Jul 2026
- Best Poker Category with a JokerPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Format and Validate a Model ResponseONSITE INTERVIEW · Seen Apr 2026
- Stateful Neuron Matrix UpdateONSITE INTERVIEW · Seen Apr 2026
- Clock Hand Angle with Subsecond PrecisionONSITE INTERVIEW · Seen Dec 2025
- Rotate an Array to the RightONSITE INTERVIEW · Seen Oct 2024
- Rich-Text Segment Normalization and Bold ToggleONSITE INTERVIEW · Seen Apr 2024
- Minimum Distance Matching in a ForestPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2024
- Shortest Distance Between Two NodesONSITE INTERVIEW · Seen Jan 2024
- Fit Beta Parameters by Maximum LikelihoodONSITE INTERVIEW · Seen Sep 2022
Similar questions at other companies
- Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
- Latest Arrival Time for a ShuttleGoogle · ONSITE INTERVIEWGoogle interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Schedule Invoice Emails and DelinquenciesStripe · ONSITE INTERVIEWStripe interview questions
- Beam Search and Nucleus DecodingMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
Scale AI interview experiences
- Scale AI OA: What It Tests (2026)
- Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
- Scale AI ML Research Engineering Intern Interviews: 1 Experience
- Scale AI SWE Intern Debugging Interview: 9 Experiences
- Scale AI New Grad SWE and MLE Question Bank
- Scale AI New Grad SWE Poker Screen and Onsite: 1 Experience