Amazon OA, AI proff question, can you suggest appraoch ?
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/2warehouses with the largest number of deliveries will become compromised. -
The remaining
k/2warehouses 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.
constraints:-
1 <= n <= 1000
1 <= k <= 1000
1 <= deliveryLogs[i] <= 1000
n - even
Example:---
n = 4
deliveryLogs = [3, 5, 9, 6]
k = 4
answer: 9If all deliveries from each log are decoded and stored separately in secure warehouses, there will be [3, 5, 9, 6] deliveries, respectively.
Considering that the two warehouses with the most deliveries will be compromised, the total secure deliveries will be:
3 + 5 = 8
If we split the 9 into 4+5, and store 5, 4, 5, 6 and ignoring 3, then our total will be 4+5 = 9


