AMAZON Coding Question – Solved

6 Live
The supply chain manager at one of Amazon's warehouses is shipping the last container of the day. All n boxes have been loaded into the truck with their sizes represented in the array `boxes`. The truck may not have enough space to store all the boxes, so some boxes may need to be unloaded. The remaining boxes must satisfy the condition: `max(boxes) ≀ space * min(boxes)`. Given the array `boxes` and an integer `space`, find the minimum number of boxes that need to be unloaded. Example: Given n = 4, boxes = [1, 4, 3, 2], and space = 2. This set already satisfies the condition, so the answer is 1 (minimum boxes to remove is 1). Function Description: Complete the function `findMaxUnloaded` in the editor below. `findMaxUnloaded` has the following parameters: - int boxes[n]: array representing the sizes of each box - int space: the multiplier Returns: - int: the minimum number of boxes to remove from the truck Constraints: - 1 ≀ n ≀ 10^5 - 1 ≀ boxes[i] ≀ 5 Γ— 10^5 - 1 ≀ space ≀ 1000 Sample Input: n = 6 boxes = [4, 5, 3, 8, 3, 7] space = 2 Sample Output: 2 Explanation: Remove boxes 4 and 6 (sizes 8 and 7). Then the maximum size of the remaining boxes is 5, the minimum size is 3, and 5 ≀ 3 * 2. Alternatively, removing boxes 3 and 5 (both size 3) leaves max = 8 and min = 4, satisfying 8 ≀ 4 * 2. So, the minimum boxes to remove is 2.

Asked in: AMAZON

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |
| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |