← Google Interview Insights

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

Intermediate
May 2026

Summary

Google SWE coding question about maximizing coins eaten from an array, where each move lets you pick three coins. Pretty clean problem on paper but the edge cases in the examples took me a bit to work through.

Questions Asked (1)

Q1

Given an array of coin counts, you can select three coins per move. What is the maximum number of coins you can eat?

Algorithms & Data Structures
Author's notes

Spent too long staring at the examples trying to reverse-engineer the rule before actually thinking about it from first principles.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and rules, such as whether the three coins must be from different piles and what happens when piles are reduced. Then, derive the mathematical condition for when a move is possible and compute the maximum number of moves (each yielding 3 coins) using a greedy or sorting-based strategy.

Pro tip: Always discuss edge cases like fewer than three piles or insufficient coins, and mention that the problem reduces to checking if the largest pile is at most the sum of the other two (after sorting). This shows you can simplify complex problems.

1. Clarify the rules

Ask if the three coins must come from different piles and whether piles can be reduced to zero. Confirm that each move removes exactly one coin from each of three distinct piles.

2. Identify the feasibility condition

For a move to be possible, there must be at least three non-empty piles. The maximum number of moves is limited by the total coins and the largest pile: if the largest pile exceeds the sum of the others, you can only make (sum of others) moves.

3. Derive the formula

Let total = sum of all coins, max = largest pile. The maximum number of moves is min(total // 3, total - max). Each move consumes 3 coins, so the answer is 3 times that number.

4. Validate with examples

Test with small cases like [1,1,1] (answer 3), [2,2,2] (answer 6), and [10,1,1] (answer 3) to ensure the formula holds and to demonstrate understanding.

5. Discuss complexity and implementation

Mention that the solution is O(n) to compute sum and max, or O(n log n) if sorting is used. Provide pseudocode or a brief explanation of how to implement it.

Key Points to Mention

  • The problem is equivalent to finding the maximum number of moves where each move reduces three distinct piles by 1.
  • The limiting factor is either the total number of coins (total // 3) or the largest pile (total - max).
  • Sorting is not strictly necessary; you only need the sum and the maximum.
  • Edge cases: fewer than three piles, empty piles, or when one pile dominates.
  • The answer is 3 times the number of moves, since each move yields 3 coins.
  • Time complexity is O(n) and space complexity is O(1) beyond input storage.

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