← 返回 rippling 的题目列表Configurable Expense Reimbursement Rule Evaluator
类型:online_judge
Problem: Configurable Expense Reimbursement Rule Evaluator
Design and implement a rule evaluator for reviewing company reimbursement requests.
The system receives an expense request, expense, and a list of JSON-configured review rules, rules. It must evaluate the request against those rules and return the decision, matched rule, and explanation.
Requirements
Rules must be represented as JSON. Adding or changing a rule must not require adding or modifying a Python/JavaScript rule class.
New, updated, or removed rules must be possible through configuration changes only; the evaluator's core logic must remain unchanged.
Support the following comparison operators:
eq, ne
gt, gte, lt, lte
in
Support logical composition:
all: every child condition matches
any: at least one child condition matches
not: the child condition does not match
Each rule contains:
id
priority (lower values run first)
when condition expression
action: approve, reject, or manual_review
reason
Evaluate rules in priority order. Return when the first terminal matching rule (approve or reject) is found. Return manual_review if no rule matches.
Expense fields may be nested, such as employee.department. Conditions must support dot-path lookup.
Example
Expense:
{
"amount": 180,
"currency": "USD",
"category": "meal",
"employee": {
"department": "Engineering",
"level": "IC"
}
}
Rules:
[
{
"id": "reject-large-meal",
"priority": 1,
"when": {
"all": [
{"field": "category", "op": "eq", "value": "meal"},
{"field": "amount", "op": "gt", "value": 200}
]
},
"action": "reject",
"reason": "Meal expenses above $200 are not reimbursable."
},
{
"id": "approve-engineering-small-expense",
"priority": 2,
"when": {
"all": [
{"field": "employee.department", "op": "eq", "value": "Engineering"},
{"field": "amount", "op": "lte", "value": 500}
]
},
"action": "approve",
"reason": "Pre-approved Engineering expense."
}
]
Expected result:
{
"action": "approve",
"matched_rule_id": "approve-engineering-small-expense",
"reason": "Pre-approved Engineering expense."
}
Describe the JSON rule schema, the evaluation engine, invalid-rule handling, and how you would extend the system with new operators or action types.
Example
Input
expense = {"amount": 180, "category": "meal", "employee": {"department": "Engineering"}}; rules = [{"id":"reject-large-meal","priority":1,"when":{"all":[{"field":"category","op":"eq","value":"meal"},{"field":"amount","op":"gt","value":200}]},"action":"reject","reason":"Too large"},{"id":"approve-eng","priority":2,"when":{"field":"employee.department","op":"eq","value":"Engineering"},"action":"approve","reason":"Engineering policy"}]
Output
{"action":"approve","matched_rule_id":"approve-eng","reason":"Engineering policy"}