Algorithmic Solutions for Competitive Programming Problems

1. Resource Allocation using Binary Search This problem requires determining the minimum capacity needed to partition a set of resources into a specific number of groups. A binary search approach is suitable here. The goal is to find the smallest value x such that the items can be covered by at most k groups, where each group has a capacity lim ...

Posted on Wed, 05 Aug 2026 16:39:25 +0000 by brianbehrens

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

Expected Key Presses in the Klavir Problem

Notation Let \(dp_i\) denote the expected number of attempts to correctly play the prefix \(1 \to i\), with \(dp_1 = n\). The target melody is given by the array \(target_i\). Analysis When playing a melody, the current partially correct sequence falls into one of two cases: The current suffix matches some prefix of the melody. No suffix of ...

Posted on Mon, 13 Jul 2026 16:09:08 +0000 by rslnerd

Comprehensive Guide to String Operations and Algorithms

Strings are fundamental data structures that store sequences of characters. In C++, strings are zero-indexed and their length can be obtained using len = s.size(). Strings can also be implemented as character arrays with len = strlen(s). Basic String Operations Insretion C++ strings support various insertion methods: string s = "abcd" ...

Posted on Sat, 27 Jun 2026 17:47:12 +0000 by healthnut

String Manipulation Algorithms: From Basics to KMP Pattern Matching

String Reversal String reversal serves as a fundamental operation in string manipulation. While most programming languages provide built-in reverse functions, understanding the underlying mechanism is crucial for technical interviews. The approach uses two pointers starting from opposite ends of the string. These pointers move toward the center ...

Posted on Mon, 01 Jun 2026 16:25:58 +0000 by tecdesign

Efficient String Partitioning via KMP Periodicity Detection

This analysis addresses the problem of decomposing a string into the minimum number of substrings such that none of the substrings are "cyclic" (periodic). A string is considered cyclic if it can be constructed by repeating a smaller substring multiple times. Given a string S of length N, we must deetrmine the minimum number of partit ...

Posted on Wed, 20 May 2026 06:01:06 +0000 by Spogliani

Solutions to AtCoder ABC 066

Problem A - Sum of Two Smallest Numbers Statement: Given three integers, output the sum of the two smallest values. Solution: Subtract the maximum value from the total sum. int a, b, c; cin >> a >> b >> c; cout << a + b + c - max({a, b, c}) << endl; Problem B - Finding the Longest Even Prefix Statement: A string i ...

Posted on Sun, 10 May 2026 03:20:54 +0000 by mynameisbob