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
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
Get started
Active Monthly Subscription Pricing
00:00
5 left

Active Monthly Subscription Pricing

MediumPython

Problem

Lendbuzz's subscription billing service stores plan changes as effective-month events. Implement a function that returns the active monthly price for a subscription during a requested month.

Each event either activates or changes the subscription price, or cancels the subscription. Events may be provided in any order. If multiple events have the same effective month, the event appearing later in the input takes precedence. An event affects its effective month and every later month until another event replaces it.

Formal Specification

Implement active_monthly_price(events, target_month).

  • events is a list of dictionaries with integer effective_month, nonnegative integer monthly_price in cents, and string status, which is either "active" or "cancelled".
  • target_month is an integer in YYYYMM format.
  • Return the active monthly price in cents as an integer. Return 0 if no event has taken effect yet or the latest applicable event is cancelled.

Constraints

  • 0 <= len(events) <= 10^5
  • 200001 <= effective_month, target_month <= 999912
  • All months are valid YYYYMM values
  • 0 <= monthly_price <= 10^9
  • status is either active or cancelled

Function Signature

def active_monthly_price(events, target_month):
Interviewer

Your question is Active Monthly Subscription Pricing. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.