Reported October 2023
ZipRecruiterprefix sum

Track Maximum and Current Rating

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

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

The mistake that sinks a first attempt on this ZipRecruiter OA is initializing the max to the first change instead of 1500. It was reported in October 2023, and it's a running prefix sum with a max tracker. Start at 1500, apply each change left to right, and keep the highest value you've seen. It's short, it's easy, and the edge cases are where people slip. If you blank under the clock, StealthCoder is the invisible safety net running on your screen during the live OA. Most candidates won't need it here, but an empty array is exactly where rushed code breaks.

The problem

Your rating starts at 1500. Apply every signed value in changes from left to right.
Return a two-element array containing:
the maximum rating observed, including the initial rating; and
the final rating after every change.

Function
trackRatingExtremes(changes: int[]) → int[]

Examples
Example 1
changes = [100,-200,350,100,-600]
return = [1850,1250]
The ratings are 1500, 1600, 1400, 1750, 1850, 1250. The maximum is 1850 and the final rating is 1250.
Example 2
changes = []
return = [1500,1500]
With no changes, both the maximum and final ratings remain at the initial value.

Constraints
0 <= changes.length <= 100000
-100000 <= changes[i] <= 100000
Every intermediate rating fits in a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there isn't one. Keep two variables, current and best, both set to 1500. Loop through changes, add each value to current, then update best with max(best, current). Return [best, current]. The pitfall is the starting value. The initial rating counts as an observation, so if every change is negative, the answer's max is still 1500. Example 1 shows the peak at 1850 mid-array, and Example 2 shows the empty case returning [1500,1500]. Don't seed best with 0 or with changes[0], and don't sort or precompute anything. One pass, O(n) time, O(1) space. With up to 100000 changes, nothing needs optimizing. Intermediate ratings fit in 32 bits, so overflow isn't a worry in most languages. If you freeze on a simple problem during the live OA, StealthCoder can hand you the loop so you can verify it against the examples and move on.

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 Track Maximum and Current Rating 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

⏵ The honest play

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

ZipRecruiter 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.

Track Maximum and Current Rating FAQ

How hard is the ZipRecruiter Track Maximum and Current Rating problem really?+

It's easy. One loop, two variables. The only real risk is a careless initialization or forgetting the empty array case. If you can write a running sum, you can solve it in a few minutes and spend the rest on checking edge cases.

What's the trick to getting the maximum rating right?+

Seed the max with 1500, not 0 and not the first change. The starting rating counts as observed. Then update the max after every addition. If all changes are negative, the answer stays 1500, which is exactly what a wrong seed would break.

What should I return when changes is empty?+

Return [1500,1500]. No changes means the max and final rating both equal the initial rating. Your loop simply never runs, so correct initialization handles this automatically without a special case. Still, test it explicitly before submitting.

Do I need to worry about overflow or performance?+

No. The constraints say every intermediate rating fits in a signed 32-bit integer, and n is at most 100000. A single O(n) pass is more than fast enough. Don't build an array of all ratings, since two variables are enough.

How do I prepare for this in 48 hours?+

Practice prefix-sum style loops with a running max, like tracking peaks in a stream. Write it once, then test with an empty array, all negatives, and all positives. That covers every case this problem can throw at you.

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

OA at ZipRecruiter?
Invisible during screen share
Get it