← Amazon Interview Insights

Amazon·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Amazon Shopping OA for a software engineering role. One algorithmic problem about a points/rewards system, pretty straightforward once you figure out what they're actually asking.

Questions Asked (1)

Q1

Given an array of n participants with pre-earned points, and a final tournament where placements award n down to 1 additional points, count how many participants could end up with the highest total score if they finish first (gaining n bonus points).

Algorithms & Data Structures
Author's notes

Took me a minute to parse what they were even asking.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: we need to count participants who, if they finish first (gaining n points), could have the highest total score, considering that others can also gain points based on their placements. The key is to check for each participant whether there exists an assignment of placements to others such that no one exceeds the participant's total. This can be done by sorting participants by their pre-earned points and using a greedy or two-pointer approach to efficiently count valid candidates.

Pro tip: Emphasize the importance of edge cases, such as ties and participants with very low initial points, and discuss how the solution scales to large n (O(n log n) time).

1. Understand the problem

Restate the problem in your own words: Given an array of initial points, if a participant finishes first (gaining n points), can they be the unique highest scorer? Count how many such participants exist. Clarify that others can also gain points from 1 to n-1 based on their placements.

2. Identify the condition for a candidate

For a candidate with initial points p, their final score is p + n. For them to be the highest, every other participant i must have initial points + bonus < p + n. Since the maximum bonus any other can get is n-1 (if they finish second), the condition simplifies to: for all i, initial_i + (n-1) < p + n, i.e., initial_i < p + 1. But this is too strict because bonuses are distinct and limited; we need to consider the assignment of bonuses.

3. Derive a necessary and sufficient condition

Sort the initial points in descending order. For a candidate with initial points p, we need to assign bonuses 1 to n-1 to the other n-1 participants such that no one exceeds p + n. The best way to avoid exceeding is to give the largest bonuses to those with the smallest initial points. So, sort others by initial points ascending, assign bonuses n-1, n-2, ..., 1 in that order, and check if any exceeds p + n. If none exceed, then the candidate is valid.

4. Optimize the check

Instead of checking each candidate independently (O(n^2)), observe that if we sort participants by initial points descending, the condition for a candidate at index k (0-based) is that for all j > k, initial_j + (n - j) <= p + n? Actually, we can use a two-pointer or prefix maximum approach. A known efficient solution: sort descending, then iterate and maintain the maximum of (initial_i + i) or similar. The candidate is valid if their score p + n is >= the maximum possible score of any other participant when optimally assigned.

5. Count valid candidates and handle ties

Count all participants for whom the condition holds. Note that if multiple participants have the same initial points, they might all be valid if the condition holds for that value. Also, consider that the candidate themselves cannot receive a bonus other than n, so the assignment for others is independent.

Key Points to Mention

  • Sorting the initial points to efficiently determine the maximum possible score of others.
  • The greedy assignment of bonuses: give larger bonuses to those with smaller initial points to minimize the maximum final score of others.
  • The condition for a candidate to be the highest: their final score (p + n) must be strictly greater than the maximum final score of any other participant under the optimal assignment.
  • Time complexity: O(n log n) due to sorting, and O(n) for the check, which is optimal.
  • Edge cases: all participants have the same initial points, or one participant has a huge lead.
  • Space complexity: O(1) extra space if sorting in place, or O(n) for a copy.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.