Reported February 2024
Googlesorting

Min Amplitude

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

You've got a Google OA in your inbox and Min Amplitude is on it. This problem sounds abstract until you realize it's about minimizing the spread of a dataset by removing elements. You're given an array and a limit on how many elements you can remove. The goal is to find the smallest range between the minimum and maximum of what's left. It's a sorting and two-pointer problem disguised as a range-minimization task. StealthCoder will have the solution ready if you blank on the approach during the live OA.

Pattern and pitfall

The trick is that sorting the array first makes the answer obvious. Once sorted, any valid subarray of length (n minus removals allowed) is a candidate answer. The amplitude of that subarray is just the difference between its last and first elements. You iterate through all valid windows, track the minimum amplitude, and return it. The common miss is not realizing that the optimal answer must be a contiguous slice of the sorted array. Most candidates overthink it and try to pick elements greedily. The pattern is straightforward sorting plus a linear scan, but the insight that contiguity holds after sorting is what separates a pass from a timeout. StealthCoder handles the edge cases around boundary checks if you're unsure mid-OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Min Amplitude 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Min Amplitude FAQ

Do I need dynamic programming for this?+

No. Sort the array, then slide a window of size (n - removals) across it. Each window's amplitude is right element minus left element. Track the minimum. That's the whole algorithm. It's O(n log n) dominated by the sort.

What if I can remove 0 elements?+

Return max(arr) - min(arr). The window size is n, so there's only one window covering the entire sorted array. That's your answer.

Can I remove more elements than the array size?+

The problem constraints will define this, but logically if removals >= n, amplitude is 0 (empty array or single element). Check the exact bounds in the OA prompt.

Is this still asked at Google in 2024?+

Yes. February 2024 candidate reported it. It's a light algorithmic problem, not a hard one. Google uses it to filter for basic pattern recognition and implementation speed. If you see it, it's a gift.

How do I code this in under 3 minutes?+

Sort. Loop i from 0 to n - k (k = max removals). For each i, compute arr[i + k - 1] - arr[i]. Track the minimum. Write it in your language of choice. Done.

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