AMAZON Coding Question – Solved

2 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

| 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… |