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

Analyzing Code Complexity

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

Your question is Analyzing Code Complexity. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

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

Problem

SIXT prices multi-day rentals with a recurrence: each additional day's cumulative rate is derived from the two previous days' cumulative rates, with a small per-day discount applied. A backend engineer wrote the recursive function below to compute the cumulative price for a rental of n days. It returns the right number for short rentals in a demo, but nobody has stated its Big O, and it has not been trusted with a real pricing run yet.

def rental_cost(n, base_rate=45.0, _trace=[]):
    _trace.append(n)

    if n == 1:
        return base_rate

    discount = 0.98
    left = rental_cost(n - 1, base_rate, _trace)
    right = rental_cost(n - 2, base_rate, _trace)
    return (left + right) * discount

State the Big O time complexity of rental_cost and explain why, in terms of the recursive calls it makes. Then point out anything else about this function you would flag before it's used to price real rentals, and explain the runtime consequence of each.