Reported November 2024
Googlegreedy

Build Maximum Integer

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

Google hit you with Build Maximum Integer in November, and you've got limited visibility into what they're really testing. This one lives in the greedy-string manipulation space. The core ask: rearrange digits (or characters) to form the largest possible number. Sounds simple until you hit the edge cases around leading zeros, digit frequency, and what "maximum" actually means in their test harness. StealthCoder will pull the exact problem statement and show you the pattern in real time if you freeze mid-OA.

Pattern and pitfall

The trick here is greedy selection: always pick the largest available digit first, then the next largest, and so on. But Google loves the catch. You'll need to handle leading zeros (can't start with 0 unless the answer is 0 itself), and you might be constrained by how many times each digit appears. Some variants ask you to use all digits; others let you skip. The pattern is sorting in descending order with careful zero handling. Common miss: forgetting the all-zeros edge case, or trying a DP approach when greedy wins. StealthCoder acts as your safety net if the problem wording is ambiguous during the live OA.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Build Maximum Integer cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as largest number. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Build Maximum Integer FAQ

Is this really just sort descending?+

Mostly yes, but Google adds a wrinkle. Leading zeros kill your answer (they don't represent a valid number). So if all digits are 0, return "0". If you have at least one nonzero, push zeros to the end after sorting. That catches most candidates.

Do I have to use every digit?+

The problem text you saw will tell you. If it's "use all digits," sort and handle zeros. If you can pick a subset, that's a harder DP problem. Read the constraint carefully in the OA itself. Google usually specifies this explicitly.

What's the time complexity?+

O(n log n) for sorting, where n is the number of digits. O(n) to build the result string. Google doesn't usually care about micro-optimizations here; correct output and clean code matter more.

Will they test negative numbers or non-digit characters?+

Unlikely for a "Build Maximum Integer" problem, but check the constraints in the OA. If the input is strictly digits 0-9, you're safe. If it's a string with letters, the problem becomes string sorting with a custom comparator.

How do I practice this in 24 hours?+

Code the greedy solution: sort descending, handle the all-zeros case, build the result. Test on a few cases: [3, 30, 34, 5], [0, 0, 0], [9, 5, 2, 1]. That covers 80% of the attack surface. Then trust the pattern.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it