All problems

Northline's Busiest Customer

hardPythonGroupByRanking

Support wants to know who to reach out to first for a "power user" interview. The interviews are run out of the branch offices, so the question is asked one city at a time: the busiest customer at a branch is the one with the most transactions on record, and where two are level on that, the one whose net balance change is larger goes first.

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 naming the branch city, spelled exactly as the city column spells it. Every city that gets asked about has at least one customer.

Task: Print the name of the customer in that city with the most transaction rows. Where two or more are tied on that count, print whichever of them has the higher net amount sum.

Example: if the busiest customer at that branch 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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…