FastPrepTop Three Accounts by Monthly Transaction Amount

Top Three Accounts by Monthly Transaction Amount

Mastercard logoMastercard● MediumFULLTIMEPHONE SCREEN

Problem statement

For each calendar month, find the accounts with the three highest distinct total transaction amounts.

Aggregate an account's transactions within the month, then apply dense ranking. Return every account whose monthly rank is at most three.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

transactions

ColumnTypeNullableDescription
transaction_idPKIntegerNo—
account_idIntegerNo—
transaction_dateDateNo—
transaction_amountDecimalNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
transaction_monthTextNo—
account_idIntegerNo—
total_transaction_amountDecimalNo—
account_rankIntegerNo—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Format transaction_month as YYYY-MM.
  • Equal totals share one rank and may produce more than three rows.
  • Sort months ascending, totals descending, and account IDs ascending.

More Mastercard problems

See Mastercard hiring insights