FastPrepFour-Player Matching Card Game
Problems/Four-Player Matching Card Game

Four-Player Matching Card Game

Scale AI logoScale AI● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Scale AI Applied AI Engineer report describes a Card and Deck model, dealing to four players and sorting their hands, matching by rank or suit, drawing a card when blocked, and returning the first player with an empty hand. We chose to play the first legal card, to not play right after drawing, and to return -1 on a stalemate. Our version is about 84% the same as the reported question.

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.

  1. Deal handSize cards to each of four players in round-robin order, then sort every hand by rank and suit.
  2. Draw the next deck card as the current card.
  3. 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.
  4. If no card matches, draw the next deck card into the hand, sort the hand, and end the turn without immediately playing it.
  5. 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) → int

Examples

Example 1

deckOrder = ["1-A","2-B","3-C","4-D","5-A"]handSize = 1return = 0

Player 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 = 1

Player 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 = -1

No hand matches rank 9 or suit E, and no draw cards remain.

Constraints

  • 1 <= handSize and 4*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
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public int matchingCardGameWinner(String[] deckOrder, int handSize) {
        // write your code here
    }
}
Checking account…