The Payroll Risk Monitor
PySpark · Intermediate · about 45 minutes
Mission
A lending team wants early warning when a customer's income drops sharply. You are building the monitor in PySpark: find each account's latest salary credit, compare it with the average of the three credits before it, and flag the accounts whose income fell by more than 40%. A monitor that fires on debits, or on accounts with too little history, is worse than none, so every rule in the specification matters.
Objective
Return the flagged accounts with the prior average, the current salary, the drop percentage and the risk flag, rounded and sorted exactly as the challenge specifies.
Skills involved
- Filtering to the relevant records
- Window ranking per account
- Aggregation with a history guard
- Combining derived datasets
- Threshold rules and rounding
Suggested preparation
Preparation is optional. The battle is written and graded in the regular challenge editor: open the battle challenge.