Question 1
Medium Given a 0-indexed array packages of N warehouse bays, minimize the total cost to clear all units. Choose one base at index 0 or N−1 and keep it for every trip. Each trip targets a bay, collects at most one unit there and at most one unit from each nonempty intermediate bay passed, then returns. Travel cost is the 1-indexed distance from the base to the furthest visited bay; handling each unit costs 1. Constraints: 1 ≤ N ≤ 10⁵ and 0 ≤ packages[i] < 10⁹. For packages = [1,2,3], the stated minimum total is 12; for [7,4,7], it is 39.
Experience
The examples include handling costs of 6 and 18 respectively. For [1,2,3], choosing the right end yields three trips with travel costs 3, 2, and 1, for total cost 12; choosing the left end costs 15 overall. For [7,4,7], symmetry gives travel cost 21 and handling cost 18, totaling 39. The candidate’s solution or performance was not reported.