AMAZON OA SDE 2

amazon logo
amazon
SDE 2
May 29, 2025 โ€ข 3 reads

Summary

This post describes two algorithmic problems encountered during an Amazon Online Assessment (OA) for an SDE 2 role, covering topics like reward distribution in a tournament and server selection with circular adjacency constraints.

Full Experience

Question 1

Amazon Shopping is running a reward collection event for its customers. There are n customers and the i-th customer has collected initialRewards[i] points so far.

One final tournament is to take place where:

The winner will be awarded n points,

The runner-up gets n - 1 points,

The third place gets n - 2 points,

...

The last place gets 1 point.

Given an integer array initialRewards of length n, representing the initial reward points of the customers before the final tournament:

๐Ÿ” Your Task Find the number of customers i (1 โ‰ค i โ‰ค n) such that, if the i-th customer wins the final tournament, they would have the highest total points.

๐Ÿง  Note: The total points = initialRewards[i] + n (if they win).

Other customers also get points in the tournament depending on their ranks (from n - 1 to 1).

You must check if the i-th customer, upon winning, ends up with the highest total score, regardless of how others place.

๐Ÿงช Example: Input: ini Copy Edit n = 3
initialRewards = [1, 3, 4] Output: Copy Edit 2 Explanation: Customer 1: 1 + 3 = 4 โ†’ Not highest, since customer 3 can get 4 + 2 = 6.

Customer 2: 3 + 3 = 6 โ†’ Yes, highest possible.

Customer 3: 4 + 3 = 7 โ†’ Yes, highest possible.

โœ… Customers 2 and 3 are valid โ†’ Answer: 2

๐Ÿงช Another Example: Input: ini Copy Edit n = 3
initialRewards = [8, 10, 9] Output: Copy Edit 2 Explanation: Customer 2: 10 + 3 = 13 โ†’ Highest.

Customer 3: 9 + 3 = 12 โ†’ Valid, since others can't beat 12 even if placed second.

โœ… Again, 2 valid customers.

Question 2

Question 2: Server Selection (AWS Horizontal Scaling) Amazon Web Services (AWS) provides highly scalable solutions for applications hosted on their servers. A company using AWS is planning to scale up horizontally and wants to buy servers from a list of available options.

Goal: Find the maximum number of servers (as a subsequence from the list) that can be rearranged so that the absolute difference between adjacent servers (including circular adjacency) is โ‰ค 1.

Conditions: A circular sequence is formed โ†’ So first and last servers are also considered adjacent.

A subsequence means elements can be removed but the order is preserved.

Formal: Given an array powers[] of n integers:

Find the maximum subsequence length such that it can be rearranged into a circular array where abs(a[i] - a[i+1]) โ‰ค 1 for all i, and abs(a[m-1] - a[0]) โ‰ค 1 where m is the length of the subsequence.

Example: text Copy Edit powers = [4, 3, 5, 1, 2, 1]

Valid Candidates:

  • [1, 2, 2, 1] โ†’ valid circular arrangement
  • [3, 1, 2, 2] โ†’ can be rearranged to [1, 2, 3, 2] which is valid

Invalid:

  • [3, 1, 2] โ†’ no rearrangement makes circular adjacent difference โ‰ค 1

Note : Converted Images to Text, so having long texts, hope it will helps aspriants for recent questions of AMAZON OA

Interview Questions (2)

Q1
Highest Total Points in Reward Collection Tournament
Data Structures & Algorithms

Amazon Shopping is running a reward collection event for its customers. There are n customers and the i-th customer has collected initialRewards[i] points so far.

One final tournament is to take place where:

The winner will be awarded n points,

The runner-up gets n - 1 points,

The third place gets n - 2 points,

...

The last place gets 1 point.

Given an integer array initialRewards of length n, representing the initial reward points of the customers before the final tournament:

๐Ÿ” Your Task Find the number of customers i (1 โ‰ค i โ‰ค n) such that, if the i-th customer wins the final tournament, they would have the highest total points.

๐Ÿง  Note: The total points = initialRewards[i] + n (if they win).

Other customers also get points in the tournament depending on their ranks (from n - 1 to 1).

You must check if the i-th customer, upon winning, ends up with the highest total score, regardless of how others place.

๐Ÿงช Example: Input: ini Copy Edit n = 3
initialRewards = [1, 3, 4] Output: Copy Edit 2 Explanation: Customer 1: 1 + 3 = 4 โ†’ Not highest, since customer 3 can get 4 + 2 = 6.

Customer 2: 3 + 3 = 6 โ†’ Yes, highest possible.

Customer 3: 4 + 3 = 7 โ†’ Yes, highest possible.

โœ… Customers 2 and 3 are valid โ†’ Answer: 2

๐Ÿงช Another Example: Input: ini Copy Edit n = 3
initialRewards = [8, 10, 9] Output: Copy Edit 2 Explanation: Customer 2: 10 + 3 = 13 โ†’ Highest.

Customer 3: 9 + 3 = 12 โ†’ Valid, since others can't beat 12 even if placed second.

โœ… Again, 2 valid customers.

Q2
AWS Server Selection (Circular Subsequence)
Data Structures & Algorithms

Question 2: Server Selection (AWS Horizontal Scaling) Amazon Web Services (AWS) provides highly scalable solutions for applications hosted on their servers. A company using AWS is planning to scale up horizontally and wants to buy servers from a list of available options.

Goal: Find the maximum number of servers (as a subsequence from the list) that can be rearranged so that the absolute difference between adjacent servers (including circular adjacency) is โ‰ค 1.

Conditions: A circular sequence is formed โ†’ So first and last servers are also considered adjacent.

A subsequence means elements can be removed but the order is preserved.

Formal: Given an array powers[] of n integers:

Find the maximum subsequence length such that it can be rearranged into a circular array where abs(a[i] - a[i+1]) โ‰ค 1 for all i, and abs(a[m-1] - a[0]) โ‰ค 1 where m is the length of the subsequence.

Example: text Copy Edit powers = [4, 3, 5, 1, 2, 1]

Valid Candidates:

  • [1, 2, 2, 1] โ†’ valid circular arrangement
  • [3, 1, 2, 2] โ†’ can be rearranged to [1, 2, 3, 2] which is valid

Invalid:

  • [3, 1, 2] โ†’ no rearrangement makes circular adjacent difference โ‰ค 1
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!