PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Debug and optimize a card-drawing strategy

Last updated: May 7, 2026

Quick Overview

This question evaluates debugging and implementation skills, combinatorial search and optimization, and the ability to design and interpret simulation-based metrics, and is commonly asked to verify correctness of stateful operations and effectiveness of different selection strategies.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Debug and optimize a card-drawing strategy

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a simplified card game engine with unit tests. The game is played using a **table** of face-up cards; each card has an integer value. On each turn, a player **draws exactly 3 cards from the table** (removing them from the table). A turn **scores 1 point** if the three drawn card values sum to **15**; otherwise it scores **0**. The game ends when fewer than 3 cards remain. ### Part 1 — Debugging A unit test fails because the current `draw_three_cards()` (or equivalent) method sometimes returns cards that were **not present on the table** at the moment of drawing. **Task:** Fix the draw method so that **all three cards are always selected from the current table state**, and the selected cards are removed from the table. ### Part 2 — Implement a naive strategy Implement a simple baseline strategy for selecting three cards each turn. Example of an acceptable baseline: - Repeatedly choose **any** triple of currently available cards whose values sum to 15 (if such a triple exists); otherwise draw any three cards. ### Part 3 — Measure strategy quality by simulation Define a way to evaluate a strategy by simulation: - Simulate many random initial deals / shuffles. - Compute the fraction of games where the strategy achieves a “perfect score” (i.e., scores 1 on every possible turn), and/or compute average total score. **Task:** Implement the evaluation harness and report the metric(s). ### Part 4 — Improve the strategy Improve the strategy to maximize total score. **Task:** Implement an optimized strategy (e.g., search/backtracking over possible sequences of draws) that attempts to maximize total points over the whole game. ### What to clarify during the interview If not already specified in the provided code/tests, state reasonable assumptions for: - How the initial table is generated (deck composition, table size). - Whether card values can repeat. - Determinism vs randomness in drawing. - What constitutes a “perfect score” in the test harness.

Quick Answer: This question evaluates debugging and implementation skills, combinatorial search and optimization, and the ability to design and interpret simulation-based metrics, and is commonly asked to verify correctness of stateful operations and effectiveness of different selection strategies.

Related Interview Questions

  • Validate Sorted Order Under a Custom Alphabet - Meta (medium)
  • Palindrome After Deleting at Most One Character - Meta (medium)
  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
|Home/Coding & Algorithms/Meta

Debug and optimize a card-drawing strategy

Meta logo
Meta
Feb 12, 2026, 12:00 AM
mediumMachine Learning EngineerOnsiteCoding & Algorithms
19
0
Practice Read
Loading...

You are given a simplified card game engine with unit tests. The game is played using a table of face-up cards; each card has an integer value.

On each turn, a player draws exactly 3 cards from the table (removing them from the table). A turn scores 1 point if the three drawn card values sum to 15; otherwise it scores 0. The game ends when fewer than 3 cards remain.

Part 1 — Debugging

A unit test fails because the current draw_three_cards() (or equivalent) method sometimes returns cards that were not present on the table at the moment of drawing.

Task: Fix the draw method so that all three cards are always selected from the current table state, and the selected cards are removed from the table.

Part 2 — Implement a naive strategy

Implement a simple baseline strategy for selecting three cards each turn.

Example of an acceptable baseline:

  • Repeatedly choose any triple of currently available cards whose values sum to 15 (if such a triple exists); otherwise draw any three cards.

Part 3 — Measure strategy quality by simulation

Define a way to evaluate a strategy by simulation:

  • Simulate many random initial deals / shuffles.
  • Compute the fraction of games where the strategy achieves a “perfect score” (i.e., scores 1 on every possible turn), and/or compute average total score.

Task: Implement the evaluation harness and report the metric(s).

Part 4 — Improve the strategy

Improve the strategy to maximize total score.

Task: Implement an optimized strategy (e.g., search/backtracking over possible sequences of draws) that attempts to maximize total points over the whole game.

What to clarify during the interview

If not already specified in the provided code/tests, state reasonable assumptions for:

  • How the initial table is generated (deck composition, table size).
  • Whether card values can repeat.
  • Determinism vs randomness in drawing.
  • What constitutes a “perfect score” in the test harness.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.