PracticeSearching

Find a Contiguous Log Marker

MediumSearchingtraversalstate trackingprefix reasoning Time not estimated Not started

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

Example 1
Input: log = "INFO user_login success"marker = "login"
Output: True
Explanation: The log contains the contiguous marker "login", so the executed result is true.
Example 2
Input: log = "WARN disk nearly full"marker = "disk full"
Output: False
Explanation: The executed result is false because the example does not contain "disk full" as the required contiguous marker.
Example 3
Input: log = "ABABAC"marker = "ABAC"
Output: True
Explanation: The log contains the contiguous marker "ABAC" starting at a later position, so the executed result is true.

Constraints

  • 1 <= len(log) <= 500
  • log: non empty
  • 1 <= len(marker) <= len(log)
  • marker: non empty
  • Types: log is str, marker is str; result is bool

Function signature

def contains_log_marker(log: str, marker: str) -> bool
log str
The complete event log to search.
marker str
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.
Approved · t3-abs_440_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1