Stripe OA 面试真题解析:Implement a Fraud Rule Engine|字符串规则、布尔规则、在线评测

3次阅读
没有评论

Implement should_accept_transaction(transaction, rules) for a fraud-rule engine.

Part 1 — String equality rules

Each transaction has string fields, such as merchant name and card brand.

Each ordered rule is either ACCEPT or BLOCK.

A rule has one equality condition, such as (merchant_name: "Not A Fraudster").

Apply rules in order; the first matching rule decides the result.

If no rule matches, accept the transaction by default.

Part 2 — Boolean, AND, and OR rules

Extend the same fraud-rule engine to support Boolean transaction fields.

A rule condition may be one Boolean variable, such as (:known_stolen_card:).

It may combine two Boolean variables with AND or OR, such as (:large_amount: AND :from_different_country:).

Keep Part 1 string-equality behavior working.

Rules are still evaluated in order, and no matching rule means accept.

这道题要求实现一个按顺序匹配的欺诈规则引擎:给定交易信息和一组规则,依次判断每条规则是否命中,命中后立即返回对应的 ACCEPT 或 BLOCK,若全部规则都不匹配,则默认接受交易。第一部分只涉及字符串字段的等值匹配,例如 merchant_name 与 card_brand;第二部分扩展到布尔字段,并支持单个布尔条件以及两个布尔条件的 AND / OR 组合。核心思路是把每条规则抽象成可求值的条件表达式,再按顺序线性扫描规则即可。

正文完
 0