AMAZON Coding Question – Solved

7 Live
The manager of an Amazon warehouse needs to ship n products from different locations, the location of the th product is represented by an array locations[i]. The manager is allowed to perform one operation at a time. Each operation is described below - If the inventory has two or more products. the manager can pick two products x and y from the inventory if they have different locations. i.e. locations[x] != locations[y] and ship both of them. - If the inventory has one or more products, the manager can pick one product x from the inventory and ship it. Note: After shipping a product it gets removed from the inventory, and the rest of the products which are currently not shipped come together keeping the order the same as before. Given n products and an array locations, find the minimum number of operations that the manager has to perform to ship all of the products Example: Given n=5 and locations=[1,8, 6, 7, 7]. The manager needs to perform 3 operations to ship all of the products. Function Description Complete the function minOperation in the editor below. minOperation has the following parameter(s): int locations[n]: the location of each products. Returns int: the minimum number of operations that locations

Asked in: AMAZON

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |