Katkat

Distinguish Permit Requirement Outcomes

PermitflowSoftware Engineer · Technical Screen

Last 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

  1. match_rules(permit_conditions): Given a list of strings representing the current state of a permit, return the outcome based on these priorities:
    • If any rule's required_conditions are a subset of the permit_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.

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

  • rules length: 0 to 1000.
  • permit_conditions length: 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`?