In a large-scale server environment, monitoring system logs is crucial for identifying anomalies, debugging issues, and ensuring smooth operations. These logs can be massive, containing millions of entries. Your task is to develop a utility that helps system administrators quickly locate specific event patterns or error signatures within a much larger master log.
Given two strings, a master_log representing the full log content and a query_pattern representing the specific event or error signature you are looking for, your goal is to find the starting index of the first occurrence of the query_pattern as a continuous substring within the master_log.
If the query_pattern does not exist anywhere in the master_log, you should return -1.
Consider the master_log and query_pattern to consist only of lowercase English alphabets.
The first line contains an integer T, indicating the number of test cases.
For each test case:
master_log string.query_pattern string.For each test case, output a single integer:
query_pattern in the master_log if found.-1 if the query_pattern is not found.1 <= T <= 501 <= master_log.length, query_pattern.length <= 1000master_log and query_pattern consist only of lowercase English alphabets ('a'-'z').Example 1: Successful Log Pattern Match
An administrator is scanning for a "connection reset" error.
master_log: "server_boot_successful_connection_reset_error_code_500" query_pattern: "connection_reset" Output: 22Explanation: The string "connection_reset" starts at index 22 of the master log "server_boot_successful_connection_reset_error_code_500".
Example 2: Pattern Not Found
Searching for a specific database error that didn't occur.
master_log: "webserver_activity_log_session_id_12345" query_pattern: "database_error" Output: -1Explanation: The string "database_error" is not present in "webserver_activity_log_session_id_12345".
Example 3: Pattern at the Beginning
The log starts with the expected server initialization message.
master_log: "system_init_complete_process_start" query_pattern: "system_init" Output: 0Explanation: The string "system_init" starts at index 0 of the master log.
String & Tries
Adobe
Start coding and your submissions will appear here.