Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Test Ancestry Campaign Event Parser

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

Your question is Test Ancestry Campaign Event Parser. Start with the requirements on the right.

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.

Problem

In the Ancestry Marketing mobile app, analytics events arrive as pipe-delimited strings. Implement a function that both parses these events and applies business rules to compute the total revenue from valid purchase events.

Each event string has the format: timestamp|event_type|user_id|campaign|amount

Your task is to process a list of event strings and return the sum of amounts for valid purchase events.

Business Rules

  1. Only events with event_type == "purchase" count toward revenue.
  2. Ignore malformed records that do not have exactly 5 fields.
  3. Ignore records where timestamp or amount is not a valid integer.
  4. Ignore records where amount <= 0.
  5. Deduplicate purchases by (timestamp, user_id). If the same purchase appears multiple times, count it only once.

Constraints

  • 1 <= len(events) <= 10^4
  • 1 <= len(events[i]) <= 200
  • Each valid record has exactly 5 pipe-delimited fields
  • timestamp and amount, when valid, fit in 32-bit signed integers

Function Signature

def total_valid_purchase_revenue(events):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output