Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Cloud Cost Efficiency Function
00:00
5 left

Cloud Cost Efficiency Function

EasyPython

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):
Interviewer

Your question is Cloud Cost Efficiency Function. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.