FastPrepMerchant Fraud Risk Scoring
Problems/Merchant Fraud Risk Scoring

Merchant Fraud Risk Scoring

Stripe logoStripe● MediumNEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: Updated August 4, 2026. A new reliable source clarifies all same-hour penalty windows, the transaction-count bound, and the no-overflow guarantee. The source still omits the complete row schemas, exact return format, and examples. The judged core task now matches the visible source at about 85%.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing this question and similar interview variations, with reported dates of October 10, 2025! ദ്ദി ˉ͈̀꒳ˉ͈́ )✧ 🩷

You are given the transactions for one day, a list of merchants with their starting fraud-risk scores, and one rule row corresponding to each transaction. Compute the final fraud-risk score of every merchant.

Input representation

  • transactions[i] = [customerId, merchantId, hour, amount], where hour and amount are base-10 strings.
  • merchantIds[j] identifies the merchant whose initial score is baseScores[j].
  • rules[i] = [minTransactionAmount, multiplicativeFactor, additiveFactor, penalty] applies to transactions[i].

Initialize each merchant's currentScore to its base score. Then perform the following three passes in order. Each pass scans the complete transaction list from left to right.

  1. Amount pass: If a transaction's amount is strictly greater than its rule's minTransactionAmount, multiply that merchant's currentScore by the rule's multiplicativeFactor.
  2. Repeat-customer pass: Track transactions by the pair (customerId, merchantId). When a pair reaches its third transaction, add the additiveFactor values of its first, second, and third transactions to that merchant's score. For every later transaction of the same pair, add only that transaction's additiveFactor.
  3. Same-hour pass: Track transactions by (customerId, merchantId, hour). Once a group reaches its third transaction, apply the first three penalty values together. For every later transaction in that group, apply only its own penalty. Add penalties when the hour is from 12 through 17, inclusive. Subtract penalties when the hour is from 9 through 11 or from 18 through 21, inclusive. For every other hour, do not change the score.

Return the final scores in the same order as merchantIds.

Function

calculateMerchantFraudScores(transactions: String[][], merchantIds: String[], baseScores: long[], rules: long[][]) → long[]

Examples

Example 1

transactions = [["c1","m1","13","120"],["c1","m1","13","80"],["c1","m1","13","90"],["c2","m2","9","50"]]merchantIds = ["m1","m2"]baseScores = [10,5]rules = [[100,2,3,4],[100,3,5,6],[100,2,7,8],[40,2,1,9]]return = [53,10]

During the amount pass, m1 changes from 10 to 20, and m2 changes from 5 to 10.

The three (c1, m1) transactions add 3 + 5 + 7 = 15. Because all three also occur during hour 13, their penalties add another 4 + 6 + 8 = 18. The final scores are [20 + 15 + 18, 10] = [53, 10].

Example 2

transactions = [["c","m","10","50"],["c","m","10","50"],["c","m","10","50"]]merchantIds = ["m"]baseScores = [4]rules = [[100,2,1,10],[100,2,2,20],[100,2,3,30]]return = [-50]

No amount exceeds its threshold. The third transaction activates the repeat-customer rule, adding 1 + 2 + 3 = 6. Because hour 10 is in the subtractive range, the same-hour pass subtracts 10 + 20 + 30 = 60. The final score is 4 + 6 - 60 = -50.

Example 3

transactions = [["c","m","12","101"],["c","m","12","101"],["c","m","12","101"],["c","m","12","101"]]merchantIds = ["m"]baseScores = [2]rules = [[100,2,1,1],[100,3,1,2],[100,2,1,3],[100,2,5,4]]return = [66]

The amount pass changes the score from 2 to 48. The repeat-customer pass adds 1 + 1 + 1 when the third transaction is reached and then adds 5 for the fourth. The same-hour pass adds 1 + 2 + 3 at the third transaction and 4 at the fourth, giving 48 + 8 + 10 = 66.

Constraints

  • 1 <= transactions.length <= 1000
  • transactions.length == rules.length
  • Every transactions[i] has exactly four fields, and every rules[i] has exactly four values.
  • 1 <= merchantIds.length == baseScores.length <= 200000
  • Merchant IDs are unique, and every transaction references a merchant in merchantIds.
  • Customer and merchant IDs are non-empty ASCII strings of length at most 40.
  • 0 <= hour <= 23
  • 0 <= amount, minTransactionAmount <= 10^9
  • 1 <= multiplicativeFactor <= 10^6
  • 0 <= baseScores[i], additiveFactor, penalty <= 10^9
  • Every intermediate and final score fits in a signed 64-bit integer.

More Stripe problems

  • Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
  • Chat Billing CalculationOA · Seen Nov 2026
  • Deployment Window SchedulerOA · Seen Nov 2026
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public long[] calculateMerchantFraudScores(String[][] transactions, String[] merchantIds, long[] baseScores, long[][] rules) {
        // Write your code here.
    }
}
Checking account…