Three LeetCode Problems: Binary Tree Split, Array Reduction, and Jump Game
Maximum Product of Splitted Binary Tree
Given a binary tree with root node, remove exactly one edge to split the tree into two separate subtrees. The goal is to maximize the product of the sums of both resulting subtrees. Return the result modulo 10^9 + 7.
Approach
The key insight is that during a depth-first search that calculates subtree sums ...
Posted on Mon, 29 Jun 2026 16:28:43 +0000 by sapoxgn
Counting Valid 2x2 Submatrices and Optimizing Zero-Prefix Products
To solve this problem, we scan every possible 2x2 submatrix in a n × m grid and check whether the four characters within it collectively contain at least one 'y', one 'o', and one 'u'. The order does not matter—only the presence of all three required characters.
The algorithm iterates over all valid top-left corners of 2x2 blocks (from row 1 to ...
Posted on Wed, 24 Jun 2026 17:58:58 +0000 by webdes03
Calculating the Maximum Path Sum in a Number Triangle
Problem Description
Given a number triangle, where each number is placed above two numbers in the row below, find the maximum possible sum of a path starting from the top and moving to adjacent numbers on the row below until the base of the triangle is reached.
For example, consider the following triangle:
7
3 8
8 1 0
2 7 4 4
4 5 2 6 ...
Posted on Sun, 21 Jun 2026 17:42:15 +0000 by PierceCoding
Probability Expectation Problem for Collecting Trading Cards
A player collects trading cards with n distinct types. Each draw yields card type i with probability pi. Duplicate cards convert to coins, where k coins can be exchanged for one missing card. The process continues until all card types are collected. Compute the expected number of draws required.
Input Format
First line: n (card types) and k (co ...
Posted on Sat, 20 Jun 2026 16:29:23 +0000 by Bootsman123
Algorithmic Problem Solutions from Competitive Programming Training
Shortest Path DAG and Convex Hull Optimization
This problem involves processing a transportation network where we need to compute both the shortest travel time and the maximum possible delay while still arriving on time.
Solution Approach
First, we construct the shortest path DAG by running Dijkstra's algorithm from the source node. Any edge no ...
Posted on Fri, 19 Jun 2026 17:23:03 +0000 by mamoman
Algorithm Solutions for Codeforces Educational Round 164
A. Ribbon Coloring Strategy
Alice's optimal strategy is to color the ribbon in a repeating pattern like "123123...". Bob's optimal counter-strategy is to recolor the ribbon to the most frequent color.
The most frequent color appears at least ⌈n/m⌉ times, leaving Bob with at most (n - ⌈n/m⌉) recoloring operations. Compare this value wi ...
Posted on Fri, 19 Jun 2026 16:00:53 +0000 by []InTeR[]
Latin America Regional Programming Contest Solutions: Advanced Algorithm Techniques
Problem D: DiviDuelo
Approach
This problem requires number theory analysis and prime factorization techniques. The solution involves categorizing cases based on the prime factorization of the input number. The implementation uses advanced primality testing and factorization algorithms including Miller-Rabin and Pollard's rho method.
Implementat ...
Posted on Thu, 18 Jun 2026 16:00:43 +0000 by sjaccaud
Optimizing Sequence Deletion for Maximum Fixed-Point Sum
Problem Statement
Given a sequence \(a_1, a_2, \dots, a_n\), select elements to delete such that the remaining subsequence maximizes the count of indices \(i\) where \(a_i = i\). The goal is to compute this maximum value.
Initial Solution and Limitations
A dynamic programming approach tracks the longest subsequence satisfying \(a_j = j\) after ...
Posted on Mon, 15 Jun 2026 18:24:25 +0000 by Htmlwiz
Understanding Simulation, DFS/BFS, Dynamic Programming, and Block Decomposition for Competitive Programming
Simulation problems, often labeled as "warm-up" or "signature" tasks in contests, require translating problem statements directly into code without relying on predefined algorithms. While they appear simple, their difficulty lies in accurately interpreting edge cases and constraints. A single oversight in boundary checks or ...
Posted on Sun, 14 Jun 2026 16:51:10 +0000 by ldougherty
Algorithmic Challenges: Modulo Operations and Dynamic Programming Strategies
Problem 1: Equalizing Elements via Modulo
Problem Statement
Given an array of integers, determine if it is possible to make all elements equal by repeatedly applying a modulo operation with an integer $x \ge 2$. In each step, every element $a_i$ is replaced by $a_i \bmod x$.
Analysis
The core constraint lies in the behavior of small numbers und ...
Posted on Sun, 14 Jun 2026 16:19:47 +0000 by asmith