Consecutive Failed Payment Attempts Before Each Meta Pay Success
Last updated: November 29, 2026
Quick Overview
For each successful Meta Pay transaction, count how many failed attempts the same user made immediately before it since their previous success, then report the distribution of that count.
Meta
November 29, 20260
0
0 solved
For each successful Meta Pay transaction, count how many failed attempts the same user made immediately before it since their previous success, then report the distribution of that count.
Payment friction shows up as retries, and Meta's payments analytics teams measure how often users fight through failures before succeeding. The interviewer is looking for the running-count grouping trick: a cumulative sum of success flags that labels each run of attempts.
What the Interviewer Expects
- Defines a group id as the number of successes strictly before each attempt
- Uses a running SUM with a frame that ends one row before the current row
- Counts failed attempts per group and attaches them to the group's success
- Drops trailing failures with no following success
- Orders by timestamp and a tie-break id
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you limit the lookback to failures within ten minutes of the success?
- How would you find users who gave up after three or more failures with no success that day?
- How would you break the distribution down by failure reason code (declined, 3DS timeout, network)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table: payment_attempts(attempt_id, user_id, attempted_at, status) with status in ('success','failed'). Attempts across different merchants still count as one user's stream for this question....
Approach
Label each attempt with the number of successes that came strictly before it: SUM(is_success) OVER (... ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING). Every run of failures plus the success that...