Audit Log Token Coverage
Context
A monitoring team keeps a catalog of approved labels used by a service. Each incoming audit log produces a list of observed labels, possibly with repetitions. Check whether the log uses only labels found in the catalog.
Problem
Given a collection of approved tokens and a collection of observed log tokens, determine whether every observed token appears somewhere in the approved collection. Treat each collection as a set for membership purposes: repeated tokens do not require repeated entries in the other collection. An observed collection with no tokens is considered fully covered. Return false as soon as a token is found that is absent from the approved collection; otherwise return true after all observed tokens have been checked.
Examples
approved_tokens = ["alpha", "beta", "gamma"]observed_tokens = ["gamma", "alpha"]Trueapproved_tokens = ["red", "green", "blue"]observed_tokens = ["red", "yellow"]Falseapproved_tokens = ["login", "logout", "error"]observed_tokens = []TrueConstraints
1 <= len(approved_tokens) <= 1001 <= len(approved_tokens[i]) <= 20 for every iapproved_tokens[i]: non emptyapproved_tokens[i]: alphabet lowercase0 <= len(observed_tokens) <= 1001 <= len(observed_tokens[i]) <= 20 for every iobserved_tokens[i]: non emptyobserved_tokens[i]: alphabet lowercase- Types:
approved_tokensis str[],observed_tokensis str[]; result is bool
Function signature
def has_token_coverage(approved_tokens: list[str], observed_tokens: list[str]) -> bool
approved_tokenslist[str]- The reference collection of approved lowercase tokens.
observed_tokenslist[str]- The collection of lowercase tokens extracted from one audit log.
- returns bool
- True if every observed token occurs in approved_tokens, including when observed_tokens is empty; otherwise false.
Adapted from MBPP problem task_706 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Repeated tokens are checked by membership only; frequency is irrelevant.
- The observed collection may be empty and is then considered covered.