Scenario
You are building a corporate employee expense card product. Admins define policies (“rules”) to prevent misuse and to flag policy violations.
You need to design a rules evaluation component that takes:
-
a list of
rules
-
a list of
expenses
(each expense is a hash map / dictionary)
and returns a result that clearly marks:
-
which
individual expenses
violate which rules
-
which
trips
(a trip is a group of expenses sharing the same
trip_id
) violate which rules
All keys and values in the input expense objects are strings.
Example rules (initial set)
Assume money is in USD.
-
Any restaurant expense must not exceed
X
dollars. (
merchant_type == "restaurant"
)
-
No airfare purchases allowed. (
category == "airfare"
)
-
No entertainment purchases allowed. (
category == "entertainment"
)
-
Any single transaction must not exceed
Y
dollars.
-
Total spend per trip must not exceed
Z
dollars.
-
Total restaurant spend per trip must not exceed
R
dollars.
Example expense object
Each expense is a dictionary like:
-
expense_id
: "001"
-
trip_id
: "001"
-
amount
: "23.312" (string)
-
purpose
: "client hosting"
-
merchant_type
: "restaurant"
-
merchant_name
: "Outback Roadhouse"
Task
Design the function:
evaluate_rules(rules: List[...], expenses: List[Dict[str, str]]) -> ???
-
Propose a
return type
(structure/schema) that supports:
-
per-expense violations
-
per-trip violations
-
clear human-readable reasons
-
machine-readable rule identifiers
-
Explain how you would design the rules representation so that
new rule types
can be added later, and rules can eventually be created via an API (i.e., emphasize extensibility and maintainability).
You do not need to write code; focus on interface and design.