Make All Elements Distinct (Amazon London)
An Amazon warehouse manager is responsible for managing inventory and ensuring that each product has a unique identifier. There are n products in the warehouse, where the identifier of the i-th item is represented by the array identifier[i]. However, in the inventory management system, some items have the same identifier.
To make all items in the inventory distinct, the following operation can be used:
- Remove the first (leftmost) item from the inventory sequence.
Given n products and the array identifier, find the minimum number of operations required to make all items in the inventory distinct.
Complete the function makeAllElementsDistinct in the editor.
makeAllElementsDistinct has the following parameters:
- 1.
n: the number of products - 2.
int identifier[n]: an array of integers representing the identifiers
Returns
int: the minimum number of operations required to make all the elements of the array distinct
1Example 1
Operations:
- Remove the first 2, resulting in [3, 2, 1, 5, 2]
- Remove the next 3, resulting in [2, 1, 5, 2]
- Remove the next 2, resulting in [1, 5, 2]
After 3 operations, identifier = [1, 5, 2], and all the elements of identifier are distinct.
Hence, the minimum number of operations required to make all the elements of the array distinct is 3.
Constraints
Limits and guarantees your solution can rely on.
๐๐