Reported September 2023
Amazonsimulation

Get Average Standing

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

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

You've got an Amazon OA from September 2023 about ranking players in a car game. The setup is straightforward: n records of d players with race id, player id, and finish time. You rank them per race (lower time wins, ties broken by lower player id), then compute their average standing across all races as a reduced fraction p/q. The trick isn't the ranking logic. It's reducing the fraction correctly and handling the edge case of players who don't race at all.

The problem

As an aspiring developer, you are required to develop a result analysis service for a car game on Amazon games. There are n even records of d players who participated in different events in form of [race id, player's id, player's time]. For some race id, a player's ranking id decided based on the increasing order of their finish time. If two players have the same finish time, the one with a lower id is ranked lower. The average standing of any player is the average of their various positions in all the races they competed in, expressed in the form of a fraction p/q. If there are multiple possible such fractions, reduce them such that p is the minimum possible. Return a 2-dimensional array where each element i contains the ith player's p and q as described above. If the player did not compete in any races, the player's p and q values are both -1. Complete the function getAverageStanding which has the following parameters:

Reported by candidates. Source: FastPrep

Pattern and pitfall

This is a simulation problem wrapped in fraction math. Step one: parse the records and group by race id. Step two: for each race, sort players by time (then by id), assign ranks 1, 2, 3, etc. Step three: for each player, collect all their ranks, compute the average, and reduce the fraction by dividing both numerator and denominator by their GCD. If a player never raced, return [-1, -1]. The common pitfall is forgetting to reduce the fraction, or reducing it wrong. GCD is your friend. Use the math.gcd function if your language has it. StealthCoder can spot the fraction reduction step if you blank on the algorithm 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 Get Average Standing 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 Amazon's OA.

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

Get Average Standing FAQ

What does 'reduce the fraction' actually mean here?+

Divide both numerator and denominator by their greatest common divisor (GCD). So 4/6 becomes 2/3. If average standing is 7/2, leave it as 7/2. The goal is the smallest p where p/q still equals the original average.

How do I handle ties in finish time?+

If two players tie on time, the one with the lower player id gets ranked higher (better position, lower number). So player 1 beats player 3 if they both finish in 10.5 seconds. Sort by time ascending, then by player id ascending.

Do I compute average as sum of ranks divided by number of races?+

Yes. If a player finishes 2nd, 5th, and 1st in three races, their average is (2+5+1)/3 = 8/3. Don't reduce until the very end, or do it as you compute to avoid overflow.

What if a player competes in only one race?+

Their average standing is their rank in that single race over 1. If they placed 4th, return [4, 1]. Reduce if needed, though usually it won't be.

Should I worry about floating point or just use integer math?+

Use integer math the whole way. Store numerator and denominator separately, compute GCD, and reduce. Never convert to float. Amazon expects exact fractions, not decimals.

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

OA at Amazon?
Invisible during screen share
Get it