Distinguish Permit Requirement Outcomes
Company: Permitflow
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Your platform helps determine whether construction projects require permits in different municipalities. The current system can record conditions under which a permit is required. If no required condition matches, it returns `NotRequired`, which is ambiguous: it may mean either that the team has confirmed no permit is required, or that the team has not researched the municipality/scope combination yet.
Modify the model so that `is_permit_required_for_scopes(project_scopes)` can distinguish between three outcomes:
1. A permit is required.
2. A permit is known not to be required.
3. The permit requirement is unknown or not yet researched.
Starter code:
```python
from enum import Enum
from typing import List
class Scope:
def __init__(self, name: str):
self.name = name
Condition = List[Scope]
class PermitRequiredStatus(Enum):
Required = "required"
NotRequired = "not_required"
class Municipality:
def __init__(self, name: str):
self.name = name
self.permit_required_conditions: List[Condition] = []
def add_permit_required_condition(self, condition: Condition):
self.permit_required_conditions.append(condition)
def is_permit_required_for_scopes(self, project_scopes: List[Scope]):
for muni_scopes in self.permit_required_conditions:
if all(muni_scope in project_scopes for muni_scope in muni_scopes):
return PermitRequiredStatus.Required
return PermitRequiredStatus.NotRequired
```
Requirements:
- Extend `PermitRequiredStatus` to include an `Unknown` value.
- Add a way to record conditions where a permit is known not to be required, such as `add_permit_not_required_condition`.
- A required condition should match when all scopes in that required condition are present in the project scopes. If any required condition matches, return `Required`.
- After checking required conditions, check known not-required conditions. A project should return `NotRequired` only if all project scopes are covered by one researched not-required condition.
- Example: if New York City has recorded that `[fence_installation]` does not require a permit, then a project with only `fence_installation` returns `NotRequired`.
- A project with `[fence_installation, hvac_replacement]` should not return `NotRequired` unless that combined set of scopes, or a condition covering both scopes, has been researched as not requiring a permit.
- If no required condition matches and no known not-required condition covers the project scopes, return `Unknown`.
- If conflicting required and not-required data exists, `Required` should take precedence.
- Add meaningful tests for required, known-not-required, unknown, mixed-scope, and conflict-precedence cases.
- You may assume `Scope` objects compare correctly by name, or implement equality by name if needed.
Quick Answer: This question evaluates software design and implementation skills, focusing on domain modeling of a tri-state permit status, condition matching via set membership, precedence handling for conflicting rules, and writing unit tests to validate business logic.