Problem
Minimum S3 Storage Cost
Learn this problemProblem statement
A batch contains files numbered from 1 to 2^n. Some files are sensitive and require encryption; their indices are given in sensitiveFiles.
For any contiguous batch of M files:
- If it contains
X > 0sensitive files, storing the whole batch costsM * X * encCost. - If it contains no sensitive files, storing the whole batch costs
flatCost.
If the batch size is even, you may either store the whole batch or split it into two equal contiguous batches and pay the sum of their optimal costs. Return the minimum possible storage cost modulo 1_000_000_007.
Function
minStorageCost(n: int, encCost: int, flatCost: int, sensitiveFiles: int[]) → intExamples
Example 1
n = 2encCost = 2flatCost = 1sensitiveFiles = [1,3]return = 6Splitting all the way to single files costs 2 + 1 + 2 + 1 = 6, which is better than keeping the full batch or only splitting once.
Example 2
n = 3encCost = 2flatCost = 1sensitiveFiles = [1,2,3,4,5,6,7,8]return = 16Every file is sensitive. Splitting into single files gives eight batches, each costing 2.
Example 3
n = 3encCost = 2flatCost = 1sensitiveFiles = [7,1]return = 8One optimal split is [1], [2], [3,4], [5,6], [7], and [8], for total cost 8.
Constraints
1 <= n <= 3 * 10^51 <= encCost, flatCost <= 10^51 <= sensitiveFiles.length <= 2^n- Each sensitive file index is between
1and2^n.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026