Distinguish Permit Requirement Outcomes
PermitflowSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to model state transitions based on complex rule sets and implement efficient logic to resolve status precedence when multiple criteria are met.
Problem Description
At Permitflow, permit statuses are determined by a set of business rules that analyze a list of active conditions. A permit can be in one of three states: APPROVED, REJECTED, or PENDING.
You are tasked with building a PermitProcessor class that evaluates a permit based on a collection of rules. Each rule has a required_conditions (a set of strings) and an outcome (the resulting status).
Requirements
match_rules(permit_conditions): Given a list of strings representing the current state of a permit, return theoutcomebased on these priorities:- If any rule's
required_conditionsare a subset of thepermit_conditions, that rule is a potential match. - If multiple rules match, precedence is defined as:
REJECTED>APPROVED>PENDING. - If no rules match, the permit defaults to
PENDING.
- If any rule's
Interface
class PermitProcessor:
def __init__(self, rules):
# rules is a list of dicts: {'conditions': {'a', 'b'}, 'outcome': 'REJECTED'}
self.rules = rules
def get_status(self, permit_conditions):
# returns 'APPROVED', 'REJECTED', or 'PENDING'
pass
Examples
Example 1
Input: rules = [{'conditions': {'zoning'}, 'outcome': 'APPROVED'}, {'conditions': {'violation'}, 'outcome': 'REJECTED'}]
permit_conditions = {'zoning', 'violation'}
Output: 'REJECTED' (Since REJECTED has higher precedence than APPROVED).
Example 2
Input: rules = [{'conditions': {'paid'}, 'outcome': 'APPROVED'}]
permit_conditions = {'submitted'}
Output: 'PENDING' (No rule matched the submitted conditions).
Constraints
ruleslength: 0 to 1000.permit_conditionslength: 0 to 50.- Precedence mapping:
{'REJECTED': 2, 'APPROVED': 1, 'PENDING': 0}.
Hints
Hint 1
Map the outcome strings to integer priorities to easily compare which permit status should take precedence.
Hint 2
A rule is satisfied if the required conditions set is a subset of the permit conditions set using the `issubset()` method or `<=`.operator.
Hint 3
Iterate through all rules, identify which ones are satisfied, and store the maximum priority outcome found.
Follow-up questions
- How would you optimize `get_status` if you had to process 1,000,000 permits against the same set of rules?
- What if some rules required 'at least one' condition from a set rather than 'all' conditions? How would your class design change?
- How would you implement a 'debug' mode that returns which specific rule caused a permit to be `REJECTED`?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.