FastPrepTransactions Within Five Minutes

Transactions Within Five Minutes

Mastercard logoMastercard● MediumFULLTIMEPHONE SCREEN

Problem statement

Find every pair of transactions made by the same customer no more than five minutes apart.

Orient each pair chronologically. When timestamps are equal, the smaller transaction ID comes first. Return the elapsed whole seconds and do not emit mirrored or self-pairs.

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—
customer_idIntegerNo—
transaction_timeTimestampNo—
transaction_amountDecimalNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
customer_idIntegerNo—
first_transaction_idIntegerNo—
second_transaction_idIntegerNo—
seconds_apartIntegerNo—

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

Constraints

  • Five minutes means at most 300 seconds, inclusive.
  • Pairs must belong to one customer.
  • Return all qualifying pairs, not only adjacent transactions.

More Mastercard problems

See Mastercard hiring insights