[Amazon] Fungible SDEI FT OA 15 Dec 2024

Code Question 1

The data analysts of Amazon are working on a prototype service to prune the data. The service takes in an array data of n integers and an integer max_distinct. It removes some elements from the array until the final array contains at most max_distinct distinct elements.

Given data and max_distinct, find the minimum number of elements the service must remove such that the resulting array contains at most max_distinct distinct elements.


Example

Suppose n = 5, data = [1, 2, 3, 2, 1], and max_distinct = 2. Some arrays with max_distinct or fewer distinct elements are shown below:

It is optimal to remove a single element 3 from the array to leave [1, 2, 2, 1] that contains only 2 distinct elements.

Hence, the answer is 1.


Function Description

Complete the function getMinRemovals in the editor below.

Function Signature:

int getMinRemovals(int data[n], int max_distinct)

Parameters:

  • int data[n]: The data passed to the service
  • int max_distinct: The maximum number of distinct elements in the final array

Returns:

  • int: The minimum number of elements to be removed from the array

Constraints

  • 1 ≤ n ≤ 100000
  • 1 ≤ data[i] ≤ 1000000000
  • 1 ≤ max_distinct ≤ 100000

Code Question 2

One of the games launched on Amazon has come up with a unique rating system for players. It is based on their relative skill levels and absolute ratings.

There are n players where the i-th player has a skill level of skill[i] and an absolute rating of rating[i].

The relative rating of the i-th player is defined as the maximum possible sum of ratings of at most k players with a skill level less than skill[i].


Example

Suppose n = 3, skill = [1, 7, 5], rating = [0, 0, 1], and k = 1.

Player Index, iBest skills to considerRelative Rating
0[]0
1[5]1
2[1]0

Explanation:

  • For player 0, no skill levels are less than 1.
  • For player 1, skill levels 5 and 1 are less, but only 5 has a relative rating greater than 0.
  • For player 2, the only skill level less than 5 is 1 with a rating of 0.

The answer is [0, 1, 0].


Function Description

Complete the function getRelativeRatings in the editor below.

Function Signature:

long int getRelativeRatings(int skill[n], int rating[n], int k)

Parameters:

  • int skill[n]: The skills of the players
  • int rating[n]: The absolute ratings of the players
  • int k: The number of top skills to consider for relative rating

Returns:

  • long int[n]: The relative ratings of the players

Constraints

  • 1 ≤ n ≤ 200000
  • 0 ≤ k ≤ n - 1
  • 1 ≤ skill[i] ≤ 1000000000
  • 1 ≤ rating[i] ≤ 1000000000

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *