Skip to main content
All Questions

Minimize the cost of backing up ordered files to S3 by splitting batches.

Unlock detailed company stats for this questionUpgrade

Function minStorageCost. Files 1..n must be backed up to S3 in order. For a batch of M files with X sensitive files, cost = M * X * encCost (only if X >= 1); a batch with 0 sensitive files costs flatCost. If a batch's size is divisible by 2, you may either store it whole or split it into two equal order-preserving halves and sum their costs. Compute the minimum storage cost, modulo 1e9+7. Splits preserve order: batch {1,4,2,6} can only split into {1,4} and {2,6}. Example: batch {1,2,3,4}, sensitiveFiles = [1,3], encCost = 2, flatCost = 1 -> 6 (split fully to singles: sensitive cost 2 each, non-sensitive 1 each). Constraints: 1 <= n <= 3 x 10^5; 1 <= encCost, flatCost <= 10^5; 1 <= K <= n.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.