Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Cloud Cost Efficiency Function

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

Your question is Cloud 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

Macquarie Group's AWS landing zone receives traffic that changes throughout the day. For each traffic interval, calculate the deployment's cost efficiency, defined as total processed requests divided by total cloud cost.

Each interval specifies the number of requests per hour and its duration in hours. The deployment launches the minimum number of instances required to handle that interval, where each instance supports a fixed number of requests per hour. Cost includes instance-hour charges and a per-request processing charge.

Formal Specification

Implement calculate_efficiency(traffic, capacity, instance_hourly_cost, request_cost).

  • traffic is a list of dictionaries, each containing integer fields requests and hours.
  • capacity is the maximum number of requests one instance can process per hour.
  • instance_hourly_cost and request_cost are non-negative costs in dollars.
  • Return a floating-point number rounded to 6 decimal places, representing requests per dollar.
  • For an interval, required instances are ceil(requests / capacity). Instances run for the entire interval duration.
  • If no requests are processed, return 0.0.

Constraints

  • 0 <= len(traffic) <= 10^5
  • 0 <= requests <= 10^9
  • 1 <= hours <= 10^4
  • 1 <= capacity <= 10^9
  • instance_hourly_cost >= 0
  • request_cost >= 0

Function Signature

def calculate_efficiency(traffic, capacity, instance_hourly_cost, request_cost):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output