FastPrepMinimum S3 Storage Cost
Problems/Minimum S3 Storage Cost

Minimum S3 Storage Cost

Amazon logoAmazonFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

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 > 0 sensitive files, storing the whole batch costs M * 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[]) → int

Examples

Example 1

n = 2encCost = 2flatCost = 1sensitiveFiles = [1,3]return = 6

Splitting 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 = 16

Every 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 = 8

One optimal split is [1], [2], [3,4], [5,6], [7], and [8], for total cost 8.

Constraints

  • 1 <= n <= 3 * 10^5
  • 1 <= encCost, flatCost <= 10^5
  • 1 <= sensitiveFiles.length <= 2^n
  • Each sensitive file index is between 1 and 2^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

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int minStorageCost(int n, int encCost, int flatCost, int[] sensitiveFiles) {
      // write your code here
    }
}
Checking account…