Staff
Number of Transactions per Visit
You are given two tables represented as arrays:
visits, where each row is[user_id, visit_date], representing thatuser_idvisited the bank onvisit_date.transactions, where each row is[user_id, transaction_date, amount], representing thatuser_idmade one transaction ofamountontransaction_date.
For each visit, count how many transactions the same user_id made on that exact visit date. Then compute a histogram where:
transactions_countis a possible number of transactions made during a visit.visits_countis the number of visits that had exactlytransactions_counttransactions.
Return the histogram as a list of [transactions_count, visits_count] pairs sorted by transactions_count in ascending order.
You must include every transactions_count from 0 through the maximum number of transactions made in any single visit. If no visit had a particular transaction count, its visits_count should be 0.
Example 1
Input
visits = [["1","2020-01-01"],["2","2020-01-02"],["12","2020-01-01"],["19","2020-01-03"],["1","2020-01-02"],["2","2020-01-03"],["1","2020-01-04"],["7","2020-01-11"],["9","2020-01-25"],["8","2020-01-28"]], transactions = [["1","2020-01-02","120"],["2","2020-01-03","22"],["7","2020-01-11","232"],["1","2020-01-04","7"],["9","2020-01-25","33"],["9","2020-01-25","66"],["8","2020-01-28","1"],["9","2020-01-25","99"]]Output
[[0,4],[1,5],[2,0],[3,1]]There are 4 visits with 0 transactions, 5 visits with 1 transaction, none with 2 transactions, and 1 visit with 3 transactions.
Example 2
Input
visits = [["1","2020-01-01"],["1","2020-01-02"],["2","2020-01-01"],["3","2020-01-01"]], transactions = [["1","2020-01-02","5"],["1","2020-01-02","10"],["3","2020-01-01","7"]]Output
[[0,2],[1,1],[2,1]]The four visits have transaction counts 0, 2, 0, and 1, so the histogram from 0 to 2 is returned.
Constraints
- 1 <= visits.length <= 10^5
- 0 <= transactions.length <= 10^5
- visits[i].length == 2
- transactions[i].length == 3
- visits[i] = [user_id, visit_date]
- transactions[i] = [user_id, transaction_date, amount]
- 1 <= user_id <= 10^5
- 1 <= amount <= 10^5
- visit_date and transaction_date are valid dates in YYYY-MM-DD format