Amazon Coding Question – Solved

4 Live
The manager of an Amazon warehouse needs to ship n products from different locations. The location of the i-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: 1. 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. 2. 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].

Asked in: Amazon

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |