Customers Withdrawing More Often Than They Deposit
A Northline risk analyst flags customers whose number of outgoing transactions (withdrawals and transfers) exceeds their number of deposits — a pattern worth a closer look, regardless of dollar amounts. The flag only means anything over a recent stretch, so the check runs over a review window whose first day is given when the report is run: somebody drawing their account down last week matters more than somebody who did it in the spring.
Customers
| id | name | account_type | city |
|---|---|---|---|
| 1 | Farah Idris | checking | Chicago |
| 2 | Grant Boyle | savings | Miami |
| 3 | Hana Suzuki | checking | Chicago |
| 4 | Ibrahim Njoku | savings | Miami |
| 5 | Jade Wu | checking | Seattle |
Transactions
| id | customer_id | amount | type | txn_date |
|---|---|---|---|---|
| 1 | 1 | 500 | deposit | 2023-07-01 |
| 2 | 1 | -120 | withdrawal | 2023-07-03 |
| 3 | 2 | 1000 | deposit | 2023-07-02 |
| 4 | 2 | -300 | withdrawal | 2023-07-05 |
| 5 | 3 | 250 | deposit | 2023-07-04 |
| 6 | 3 | -600 | withdrawal | 2023-07-06 |
| 7 | 4 | 800 | deposit | 2023-07-07 |
| 8 | 4 | -450 | withdrawal | 2023-07-08 |
| 9 | 5 | 2000 | deposit | 2023-07-09 |
| 10 | 5 | -1500 | withdrawal | 2023-07-10 |
| 11 | 1 | -200 | transfer | 2023-07-11 |
| 12 | 3 | 400 | deposit | 2023-07-12 |
Input
Both tables above are already built for you — those rows are not read from input. What does arrive is a single line holding the first day of the review window, written the same way txn_date writes its dates.
Task: Looking only at transactions dated on or after that day, compare each customer's number of "deposit" rows against their number of non-deposit rows. Print a sorted list of the names whose outgoing rows outnumber their deposits. A window with no transactions in it gives an empty list rather than an error.
Example: if one customer were flagged and she were called Ada Reyes, you'd print ['Ada Reyes'].
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in