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
Phone Log Parsing and Billing
00:00
5 left

Phone Log Parsing and Billing

MediumPython

Problem

Write a function which parses a string describing a phone log, calculates how much to charge for each call, and includes test cases as needed.

Implement def calculate_call_charges(log):; log contains newline-separated records in the form HH:MM:SS, phone_number, where the first field is the call duration, and return a list of dictionaries in input order.

Charge calls of 5 minutes or less at 3 cents per second; longer calls cost 150 cents for each started 5-minute block. Ignore blank lines, preserve the trimmed phone number, and assume nonblank records are valid.

Constraints

  • 1 <= number of nonblank records <= 5000
  • Each duration has the form HH:MM:SS and represents a nonnegative duration
  • Each phone number is nonempty after trimming
  • Each nonblank record contains exactly one comma separating duration and phone number
  • All charges must be returned as integer cents

Function Signature

def calculate_call_charges(log):
Interviewer

Your question is Phone Log Parsing and Billing. 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.