Trie Data Structure for Efficient String Matching and Filtering

Trie, also known as a prefix tree, is a tree-like data structure that stores strings by sharing common prefixes among them. This design optimizes space usage when handling sets of strings with overlapping beginnings. For instance, strings "abc" and "abd" share the prefix "ab," allowing a single path for "ab&qu ...

Posted on Thu, 13 Aug 2026 16:12:01 +0000 by raptorman

Problem Set Solutions: Discrete Mathematics and Graph Construction

Problem A Given a prime (P=10^{18}+31) with primitive root (g=42), define array (A) as: [ A_i=\begin{cases} 795484359100928850 & i=0 \ \log_g A_{i-1} \bmod P & i>0 \end{cases} ] For multiple queries, output (A_x). Constraints: (1\le T\le 10), (0\le x\le 10^5). Solution: The value (A_{100000}) is provided in the problem. We can recove ...

Posted on Wed, 29 Jul 2026 16:48:20 +0000 by Lamez

Mastering KMP for String Matching: Implementing strStr and Detecting Repeated Substrings

Implementing strStr() with the KMP Algorithm Given a haystack string and a needle string, locate the index of the first occurrence of the needle. The Knuth–Morris–Pratt (KMP) algorithm avoids redundant comparisons by precomputing a prefix table (often called the LPS – Longest Proper Prefix which is also Suffix – array). First, construct the LPS ...

Posted on Wed, 22 Jul 2026 16:42:34 +0000 by wizhippo

XCPC Nanjing Regional Problem Solutions: B, G, and H

Problem B: What, More Kangaroos? Operations 1 and 2 nullify eachother, as do operations 3 and 4. The problem reduces to applying positive integer operations on two buttons only, yielding four enumeration cases. With operations 1 and 3 chosen, let operation 1 execute x times and operation 3 execute y times (x, y > 0). The goal is maximizing i ...

Posted on Mon, 06 Jul 2026 17:09:43 +0000 by jgetner

Comprehensive Guide to Using Regular Expressions in Python

Overview Python's re module provides powerful tools to pattern matching within strings. The basic syntax for matching is: import re result = re.match(pattern, string) When using regular expressions, it's essential to prefix the pattern with an r to prevent Python from interpreting backslashes as escape characters. Matching Single Characters ...

Posted on Thu, 07 May 2026 05:15:27 +0000 by Sealr0x