Find a Contiguous Log Marker
Context
The monitoring team stores each event stream as one text line. A marker phrase identifies a notable incident only when its characters appear next to one another in the log. Create a checker that searches the full log for the marker without treating separated characters as a match.
Problem
Given a source log string and a marker string, determine whether the marker occurs as one contiguous segment of the log. Characters must match in order and without gaps. Check candidate starting positions from left to right. While characters match, advance through both strings. If a comparison fails, abandon that candidate and begin from the next source position. Return true only after every marker character has matched; return false if no candidate remains.
Examples
log = "INFO user_login success"marker = "login"Truelog = "WARN disk nearly full"marker = "disk full"Falselog = "ABABAC"marker = "ABAC"TrueConstraints
1 <= len(log) <= 500log: non empty1 <= len(marker) <= len(log)marker: non empty- Types:
logis str,markeris str; result is bool
Function signature
def contains_log_marker(log: str, marker: str) -> bool
logstr- The complete event log to search.
markerstr- The contiguous character sequence that must be found in the log.
- returns bool
- Return true if marker appears contiguously in log, and false otherwise.
Adapted from MBPP problem task_576 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Characters are compared exactly, including case and punctuation if present.