Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cloud Storage Cost-Efficiency Function

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Cloud Storage Cost-Efficiency Function. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

For a dentsu cloud analytics workload, each object can be stored in one of several tiers. Calculate the monthly cost of every valid tier for each object, then assign the object to its cheapest tier.

Each object's access pattern includes its stored size, number of reads per month, and total gigabytes retrieved. A tier's cost consists of storage, read requests, and retrieval fees. Return the minimum total monthly cost and the selected tier for each object, preserving input order.

Formal Specification

Implement optimize_storage_cost(objects, tiers).

  • objects is a list of dictionaries containing name, size_gb, reads, and retrieved_gb.
  • tiers is a list of dictionaries containing name, storage_per_gb, request_per_1000, and retrieval_per_gb.
  • Storage, request, and retrieval values are non-negative numbers representing monthly dollars.
  • Return a dictionary with total_cost, rounded to two decimal places, and assignments, a list of dictionaries containing each object's name and selected tier name.

The cost of assigning an object to a tier is: size_gb * storage_per_gb + reads / 1000 * request_per_1000 + retrieved_gb * retrieval_per_gb.

Constraints

  • 1 <= len(objects) <= 10^4
  • 1 <= len(tiers) <= 10
  • 0 <= size_gb, reads, retrieved_gb <= 10^9
  • All prices are non-negative numbers
  • Each object has at least one available tier

Function Signature

def optimize_storage_cost(objects, tiers):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output