← 返回 rippling 的题目列表Expense Transaction Rule Evaluator
类型:online_judge
Problem: Expense Transaction Rule Evaluator
Implement a simplified expense compliance checker. Given a list of employee expense transactions and a list of compliance rules, determine which rules are violated by each transaction.
Input Format
Standard input contains one JSON object:
{
"transactions": [
{
"id": "t1",
"employee": "alice",
"amount": 1200,
"merchant": "Apple",
"category": "electronics",
"country": "US",
"timestamp": 1710000000
}
],
"rules": [
{
"id": "max_amount",
"conditions": [
{"field": "amount", "op": ">", "value": 1000}
]
}
]
}
Rule Definition
Each rule contains:
id: the rule ID.
conditions: a list of conditions.
A transaction violates a rule if and only if all conditions in that rule are satisfied. Conditions inside one rule are combined using logical AND.
Each condition contains:
field: the transaction field to check.
op: the comparison operator.
value: the value to compare against.
Supported operators:
| op | Meaning | |---|---| | == | equal to | | != | not equal to | | > | greater than | | >= | greater than or equal to | | < | less than | | <= | less than or equal to | | in | transaction field value is in the value array | | not_in | transaction field value is not in the value array |
Additional Rules
If a condition references a missing field, that condition is false.
If a numeric comparison is applied to non-comparable values, that condition is false.
A rule with an empty conditions list matches every transaction.
Output transactions in the same order as the input.
For each transaction, output violated rule IDs in the same order as the input rules.
Output Format
Output a JSON array:
[
{
"transaction_id": "t1",
"violated_rules": ["max_amount"]
}
]
Constraints
1 <= len(transactions) <= 10000
1 <= len(rules) <= 500
Each rule has at most 20 conditions.
Transaction field values may be strings, numbers, booleans, or null.
Example
Input
{"transactions":[{"id":"t1","employee":"alice","amount":1200,"merchant":"Apple","category":"electronics","country":"US","timestamp":1710000000},{"id":"t2","employee":"bob","amount":50,"merchant":"Cafe","category":"food","country":"US","timestamp":1710000100}],"rules":[{"id":"max_amount","conditions":[{"field":"amount","op":">","value":1000}]}]}
Output
[{"transaction_id":"t1","violated_rules":["max_amount"]},{"transaction_id":"t2","violated_rules":[]}]