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
Count Users Per Funnel Step
00:00
5 left

Count Users Per Funnel Step

HardPython

Problem

Faire tracks user activity as an event log while merchants move through an ordered product funnel, such as view_store, add_product, and request_order. Given the chronological events and the funnel steps, return how many unique users reached each step in sequence.

A user advances only when their event matches their next expected step. Duplicate events for a completed step are ignored, and an event for a later step cannot skip an earlier step. Events are already ordered chronologically.

Formal Specification

Implement count_funnel_users(events, steps).

  • events is a list of dictionaries, each with a string user_id and a string step.
  • steps is a list of distinct strings defining the funnel order.
  • Return a list of integers where position i is the number of unique users who reached steps[i] after completing every previous step.
  • If steps is empty, return an empty list.

Constraints

  • 0 <= len(events) <= 10^5
  • 0 <= len(steps) <= 10^3
  • Each event contains a non-empty string user_id and step
  • Event order is chronological
  • Every step name is unique

Function Signature

def count_funnel_users(events, steps):
Interviewer

Your question is Count Users Per Funnel Step. 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.