KatInterview

Evaluate Request Status from Rule Matches

Arrays & HashingAuto-graded · 21 test cases
MediumAuto-gradedArrays & Hashingset-operationslogicprecedence

Last updated

Tests rule-based decision logic with subset matching and outcome priority resolution when multiple rules apply simultaneously.

You are building a system that determines the status of incoming requests by evaluating them against a collection of decision rules.

Each rule consists of:

  • A set of required criteria (strings)
  • An outcome status: one of "APPROVED", "REJECTED", or "PENDING"

Given a list of rules and the criteria present on a particular request, determine the final status:

  1. A rule applies when all of its required criteria appear in the request's criteria list
  2. Multiple rules may apply to the same request
  3. When multiple rules apply, the final status follows this priority order:
    • "REJECTED" (highest priority)
    • "APPROVED" (medium priority)
    • "PENDING" (lowest priority)
  4. If no rules apply, the default status is "PENDING"

Write a function that takes a list of rules and a list of request criteria, then returns the final status string.

Input Format:

  • rules: A list of dictionaries, each containing:
    • "conditions": A list of strings (the required criteria)
    • "outcome": A string ("APPROVED", "REJECTED", or "PENDING")
  • request_criteria: A list of strings representing the criteria present on this request

Output Format:

  • Return a single string: "APPROVED", "REJECTED", or "PENDING"

Constraints

  • Number of rules: 0 ≤ len(rules) ≤ 1000
  • Number of request criteria: 0 ≤ len(request_criteria) ≤ 50
  • Each criterion string is non-empty
  • Request criteria may contain duplicates
  • Rule conditions may be provided as lists, sets, or tuples
  • Only the three specified outcome values will appear

Examples

Example 1

Input: evaluate_request_status([{'conditions': ['zoning'], 'outcome': 'APPROVED'}, {'conditions': ['violation'], 'outcome': 'REJECTED'}], ['zoning', 'violation'])

Output: 'REJECTED'

Example 2

Input: evaluate_request_status([{'conditions': ['paid'], 'outcome': 'APPROVED'}], ['submitted'])

Output: 'PENDING'

Example 3

Input: evaluate_request_status([{'conditions': ['submitted'], 'outcome': 'PENDING'}, {'conditions': ['submitted', 'paid'], 'outcome': 'APPROVED'}], ['submitted', 'paid'])

Output: 'APPROVED'

Hints

Hint 1

Convert the request criteria to a set for efficient membership checking

Hint 2

Use Python's set.issubset() to test whether all required criteria are present

Hint 3

Map each outcome to a numeric priority and track the maximum priority seen