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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free

Analyzing Code Complexity

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

Whenever you're ready, walk me through how you'd approach this.

Sign up free to chat or submit. Log in

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.