This is a verified interview question from Amazon. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Secure Maximum Deliveries - Amazon Online Assessment Hackon" covers key patterns like Arrays.
"As a logistics manager in an automobile manufacturing company, you are responsible for storing deliveries in secure warehouses. You are given an array `deliveryLogs` of size `n`, where each element represents the number of parts delivered in the `i-th` log. You are also given an even integer `k`, representing the number of secure warehouses available. When deliveries are stored: * Each warehouse can store deliveries taken from a single delivery log only. Deliveries from different logs cannot be mixed in the same warehouse, but deliveries from a single log may be split across multiple warehouses. * After storing, exactly `k/2` warehouses with the **largest** number of deliveries will become compromised. * The remaining `k/2` warehouses are safe, and only the deliveries in them are counted as secure. Your task is to find the maximum number of secure deliveries that can be stored. --- ### Function Description Complete the function `secureMaximumDeliveries`. `secureMaximumDeliveries` has the following parameter(s): * `int deliveryLogs[n]`: the number of deliveries in the `i-th` encrypted log. * `int k`: the number of secure warehouses you have. **Returns:** * `int`: the maximum number of secure deliveries you can make. --- ### Constraints * `1 <= n <= 1000` * `2 <= k <= 1000` * `0 <= deliveryLogs[i] <= 1000` * It is guaranteed that `k` is an even integer. --- ### Sample Test Cases #### Sample Case 0 **Sample Input 0** ```text n = 1 deliveryLogs = [6] k = 2 ``` **Sample Output 0** ```text 3 ``` **Explanation** If we decode half the deliveries and store them in the first secure warehouse, then decode the remaining half and store them in the second warehouse, each warehouse will have three deliveries. One of these warehouses will be compromised since they have an equal number of deliveries, so the remaining secure deliveries will be 3. #### Sample Case 1 **Sample Input 1** ```text n = 6 deliveryLogs = [5, 5, 5, 5, 5, 5] k = 4 ``` **Sample Output 1** ```text 10 ``` **Explanation** Decrypt all the deliveries in any of the four logs and store them in the secure warehouses. Now, all secure warehouses have five deliveries each. After two warehouses are compromised, the total secure deliveries are 5 + 5 = 10."
Join thousands of developers practicing for Amazon.