Transaction Rule Expression Evaluator
Problem statement
Evaluate deny rules against transactions. Each transaction row is [id, amount, country, cardPresent], where amount is a non-negative integer and cardPresent is true or false.
Every rule is a space-separated expression. A condition has the form field operator value. Fields are amount, country, and cardPresent. String and boolean fields support == and !=; amount additionally supports <, <=, >, and >=. Parentheses are separate tokens. AND and OR have equal precedence and are evaluated left to right within each parenthesized level.
A transaction is denied when any complete rule evaluates to true. Return id|DENY or id|ACCEPT for each transaction in input order.
Function
evaluateTransactions(transactions: String[][], rules: String[]) → String[]Examples
Example 1
transactions = [["t1","150","US","false"],["t2","40","CA","true"],["t3","70","US","true"]]rules = ["amount > 100 AND country == US","cardPresent == false AND amount >= 50"]return = ["t1|DENY","t2|ACCEPT","t3|ACCEPT"]t1 matches both deny rules; the other transactions match neither.
Example 2
transactions = [["a","20","US","false"],["b","20","CA","false"]]rules = ["( country == US OR country == MX ) AND cardPresent == false"]return = ["a|DENY","b|ACCEPT"]The nested country expression is true only for transaction a.
Constraints
1 <= transactions.length, rules.length <= 10^4.- Every row has four valid fields and every transaction ID is unique.
- Every rule is syntactically valid, has at most 200 tokens, and parentheses are balanced.
- Country values are non-empty uppercase ASCII identifiers without spaces.