PracticeHashing

Audit Log Token Coverage

EasyHashingset membershiptraversalstate tracking Time not estimated Not started

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

Example 1
Input: approved_tokens = ["alpha", "beta", "gamma"]observed_tokens = ["gamma", "alpha"]
Output: True
Explanation: In executed example 1, the function returns true, and the final traced all_match value is true.
Example 2
Input: approved_tokens = ["red", "green", "blue"]observed_tokens = ["red", "yellow"]
Output: False
Explanation: In executed example 2, the function returns false, and the final traced all_match value is false.
Example 3
Input: approved_tokens = ["login", "logout", "error"]observed_tokens = []
Output: True
Explanation: In executed example 3, the function returns true for the empty observed collection.

Constraints

  • 1 <= len(approved_tokens) <= 100
  • 1 <= len(approved_tokens[i]) <= 20 for every i
  • approved_tokens[i]: non empty
  • approved_tokens[i]: alphabet lowercase
  • 0 <= len(observed_tokens) <= 100
  • 1 <= len(observed_tokens[i]) <= 20 for every i
  • observed_tokens[i]: non empty
  • observed_tokens[i]: alphabet lowercase
  • Types: approved_tokens is str[], observed_tokens is str[]; result is bool

Function signature

def has_token_coverage(approved_tokens: list[str], observed_tokens: list[str]) -> bool
approved_tokens list[str]
The reference collection of approved lowercase tokens.
observed_tokens list[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.
Approved · c003-abs_106_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1