Loading content...
A financial monitoring service tracks account-level transaction activity and monthly risk limits.
Table: Accounts
Table: Transactions
Business rule: An account is considered high-risk if its total monthly incoming amount (sum of Creditor amounts) exceeds max_income in at least two consecutive calendar months.
Task: Return the IDs of all accounts that satisfy this risk rule.
Output requirements:
Supported submission environments:
Accounts:
| account_id | max_income |
|------------|------------|
| 3 | 21000 |
| 4 | 10400 |
Transactions:
| transaction_id | account_id | type | amount | day |
|----------------|------------|----------|--------|---------------------|
| 2 | 3 | Creditor | 107100 | 2021-06-02 11:38:14 |
| 10 | 3 | Creditor | 102100 | 2021-06-15 10:37:16 |
| 7 | 3 | Creditor | 90900 | 2021-06-14 11:23:07 |
| 8 | 3 | Creditor | 64900 | 2021-07-26 15:09:56 |
| 1 | 4 | Creditor | 49300 | 2021-05-03 16:11:04 |
| 4 | 4 | Creditor | 10400 | 2021-06-20 12:39:18 |
| 14 | 4 | Creditor | 56300 | 2021-07-21 12:12:25 |
| 11 | 4 | Debtor | 58800 | 2021-07-23 12:41:55 |[
{"account_id":3}
]Account 3 exceeds its limit in June and July consecutively. Account 4 exceeds in May and July but not in June, so it is not flagged.
Accounts:
| account_id | max_income |
|------------|------------|
| 1 | 5000 |
| 2 | 9000 |
Transactions:
| transaction_id | account_id | type | amount | day |
|----------------|------------|----------|--------|---------------------|
| 1 | 1 | Creditor | 5000 | 2024-01-11 10:00:00 |
| 2 | 1 | Creditor | 4900 | 2024-02-11 10:00:00 |
| 3 | 2 | Debtor | 2000 | 2024-01-20 09:00:00 |
| 4 | 2 | Creditor | 8000 | 2024-03-02 12:00:00 |[]No account exceeds max_income in two consecutive months. Equality with max_income is not considered an exceed event.
Accounts:
| account_id | max_income |
|------------|------------|
| 10 | 12000 |
| 11 | 5000 |
Transactions:
| transaction_id | account_id | type | amount | day |
|----------------|------------|----------|--------|---------------------|
| 101 | 10 | Creditor | 13000 | 2020-12-04 08:00:00 |
| 102 | 10 | Creditor | 15000 | 2021-01-09 08:30:00 |
| 103 | 11 | Creditor | 6000 | 2021-01-02 08:30:00 |
| 104 | 11 | Creditor | 4000 | 2021-02-02 08:30:00 |[
{"account_id":10}
]Consecutive-month detection must work across year boundaries (December to January).
Constraints