Minimum S3 Storage Cost
Updated
Problem statement
You have one batch of files numbered 1 to 2^n. Some files are sensitive and must be encrypted. Their numbers are listed in sensitiveFiles.
Here is the cost to store a batch of M files with consecutive numbers:
- If it holds
X > 0sensitive files, storing the whole batch costsM * X * encCost. - If it holds no sensitive files, storing the whole batch costs
flatCost.
If a batch has an even number of files, you have a choice. You can store it whole. Or you can split it into its first half and its second half. Each half is then stored in its cheapest way, by the same rules, and you pay the sum of the two.
Return the minimum cost to store the full batch, 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. The total is sixteen.
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 Online Assessment questions
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Nov 2026