← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026Mountain View

Summary

Google onsite coding round in Mountain View, mahjong hand detection as the main problem. The prompt was intentionally vague which meant the first few minutes were basically just clarification questions before any code got written.

Questions Asked (1)

Q1

Given an array of 14 integers representing mahjong tiles, determine whether the hand is a winning hand (one pair plus four melds, where each meld is either a triplet or a run of three consecutive ranks).

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The problem statement they give you is basically nothing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the rules (tile ranks, meld definitions, and whether suits matter) and then design a recursive backtracking algorithm that tries all possible pairs and melds. Explain the algorithm, analyze its complexity, and discuss potential optimizations like memoization or pruning.

Pro tip: Demonstrate strong problem-solving by first handling the edge case of invalid tile counts (e.g., total tiles not 14) and then discussing how to adapt the solution if the rules change (e.g., multiple suits or additional meld types).

1. Clarify the problem

Ask about tile representation (e.g., integers 1-9 for ranks, possibly suits), meld definitions (triplet = three identical, run = three consecutive), and winning condition (one pair + four melds). Confirm that the hand has exactly 14 tiles.

2. Choose an algorithm

Propose a recursive backtracking approach: try each possible pair, then recursively attempt to form four melds from the remaining tiles. Alternatively, use dynamic programming or memoization to avoid redundant checks.

3. Implement and test

Write pseudocode for the backtracking function, ensuring it handles tile counts correctly. Test with edge cases: winning hand, near-winning hand, invalid tile counts, and hands with multiple possible pairs.

4. Analyze complexity and optimize

Discuss time complexity (e.g., O(n^2) or exponential in worst case) and space complexity. Suggest optimizations like sorting tiles, using a frequency map, and pruning branches early.

5. Discuss trade-offs and extensions

Compare backtracking with other approaches (e.g., greedy, DP) and explain why backtracking is suitable. Mention how to extend the solution for multiple suits or additional meld types.

Key Points to Mention

  • Tile representation: integers 1-9 for ranks, possibly suits if multiple suits are allowed.
  • Meld definitions: triplet (three identical) and run (three consecutive ranks).
  • Winning condition: exactly one pair and four melds, totaling 14 tiles.
  • Backtracking algorithm: try each pair, then recursively form melds.
  • Complexity analysis: worst-case exponential, but optimizable with memoization and pruning.
  • Edge cases: invalid tile counts, multiple possible pairs, and hands with no valid melds.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.