Company: Amazon Sde1_1may
Difficulty: medium
The manager of the Amazon warehouse has decided to make changes to the inventory. Currently, the inventory has n products, where the quality of the i th product after quality checks is represented by the array element quality[i] . The manager wants to create an optimal inventory, where the array of products quality follows the following property: All occurrences of each quality value must be contiguous. In order to convert the inventory into an optimal inventory, the manager can do the following operation any number of times: Choose two quality values x and y . Replace every product with quality x to have quality y instead. This operation costs num_replacements units of money, where num_replacements is the number of products whose quality was changed. Given n products and an array quality , find the minimum amount of money the manager has to spend to convert the inventory into an optimal inventory. Note: The quality of a product can be negative indicating that the product is of poor qu