Analyze Returning Borrowers Across Two Days of Logs
Quick Overview
Analyze two days of loan activity to find users who appear on both days and have at least two distinct loan types across their combined records. Retain an extensible per-user aggregate for an injected trust policy, with clear duplicate, ordering, complexity, and test semantics.
Analyze Returning Borrowers Across Two Days of Logs
Company: Affirm
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
# Analyze Returning Borrowers Across Two Days of Logs
You receive two collections of loan-activity records, one for each of two consecutive days. Each record contains `user_id` and `loan_type`; the same pair may appear multiple times.
Design a Python solution that:
1. Returns the users who appear on both days and have at least two distinct loan types across the union of both days.
2. Builds a per-user aggregate that can be passed to an interviewer-supplied `trust_policy(aggregate)` function without redesigning the first part.
The trust formula is deliberately not specified. Treat the policy as an injected pure function; do not invent its business rules. Explain your data structures, result ordering, complexity, and how you would test the aggregation boundary.
### Clarifying Questions to Ask
- Does “at least two loan types” apply to each day or to the two-day union?
- Are duplicate records meaningful beyond presence?
- What deterministic output order is required?
- Which aggregate fields does the trust policy contract require?
### What a Strong Answer Covers
- Correct eligibility logic with explicit day-membership, distinctness, duplicate, and ordering semantics
- A clear, extensible aggregate rather than coupling to an unknown score formula
- Explicit duplicate and ordering semantics
- Complexity proportional to the input plus output, with focused tests for boundary cases
### Follow-up Questions
1. How would the design change for a rolling 30-day window?
2. How would you process logs that do not fit in memory?
3. What if trust policies are versioned and old scores must be reproducible?
4. Which checks prevent malformed records from silently changing eligibility?
Quick Answer: Analyze two days of loan activity to find users who appear on both days and have at least two distinct loan types across their combined records. Retain an extensible per-user aggregate for an injected trust policy, with clear duplicate, ordering, complexity, and test semantics.
Analyze Returning Borrowers Across Two Days of Logs
You receive two collections of loan-activity records, one for each of two consecutive days. Each record contains user_id and loan_type; the same pair may appear multiple times.
Design a Python solution that:
Returns the users who appear on both days and have at least two distinct loan types across the union of both days.
Builds a per-user aggregate that can be passed to an interviewer-supplied
trust_policy(aggregate)
function without redesigning the first part.
The trust formula is deliberately not specified. Treat the policy as an injected pure function; do not invent its business rules. Explain your data structures, result ordering, complexity, and how you would test the aggregation boundary.
Clarifying Questions to Ask Guidance
Does “at least two loan types” apply to each day or to the two-day union?
Are duplicate records meaningful beyond presence?
What deterministic output order is required?
Which aggregate fields does the trust policy contract require?
What a Strong Answer Covers Guidance
Correct eligibility logic with explicit day-membership, distinctness, duplicate, and ordering semantics
A clear, extensible aggregate rather than coupling to an unknown score formula
Explicit duplicate and ordering semantics
Complexity proportional to the input plus output, with focused tests for boundary cases
Follow-up Questions Guidance
How would the design change for a rolling 30-day window?
How would you process logs that do not fit in memory?
What if trust policies are versioned and old scores must be reproducible?
Which checks prevent malformed records from silently changing eligibility?