Reported August 2024
Googlegreedy

Find Max Heart Rate Difference

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's max heart rate difference question hits candidates in August, and it's usually a trap disguised as a simple array problem. You're staring at a list of heart rate readings and need to find the maximum difference between any two values. The surface answer is obvious: max minus min. But Google rarely asks for that. The real test is whether you're thinking about constraints, time complexity, or a hidden twist like subsequences, constraints on indices, or a specific pattern in the data you need to uncover.

Pattern and pitfall

This is typically an array traversal problem, often with a greedy or dynamic-programming hedge. The naive solution is O(n) in one pass: track the minimum value seen so far and compute the difference with each new element as you go. But Google's version often adds a constraint you miss on first read. It might be asking for the max difference where the higher value comes after the lower, which still works with single-pass greedy. Or it's asking for max difference across a sliding window, or within a time window, or excluding outliers. The pattern is either greedy (track min, compute max diff) or prefix-sum (precompute mins up to each point). If you blank on the live OA, StealthCoder reads the full constraint set and delivers the right approach instantly.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Find Max Heart Rate Difference 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as best time to buy and sell stock. 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Max Heart Rate Difference FAQ

Is this just max minus min?+

Probably not. Google's version usually constrains which two values you can compare: often the larger must come after the smaller in the array, or there's a time or index constraint. Read the problem statement twice before coding. The twist is always in the constraints.

What's the time complexity I need?+

O(n) in a single pass is the target. Track the minimum value you've seen so far, then for each new element compute the difference and update the max. No sorting, no nested loops. If the interviewer pushes back, the problem is definitely about handling the constraint correctly, not optimization.

Do I need dynamic programming?+

Not usually. Greedy (track running min) solves most versions. DP comes in only if the problem asks for a max difference across non-adjacent elements or within a specific window. Check the constraints first. If they're silent, assume greedy is the answer.

How do I prepare for this in 48 hours?+

Understand the greedy single-pass approach cold. Practice on LeetCode Best Time to Buy and Sell Stock, which is the canonical version of this pattern. Then trace through the Google problem once you have the full text. The trick is in reading, not in the algorithm.

What's the common failure?+

Candidates code max(array) minus min(array) and submit. That's wrong if the constraint is directional (larger value must come after smaller). Test your solution on a descending array like [5, 4, 3, 2, 1]. If it returns 4, you failed the constraint check.

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