Generating Combinations with Backtracking
The task is to generate all possible combinations of r distinct numbers from the set {1, 2, ..., n}. A combination is an unordered selection, meaning {1, 2, 3} is the same as {3, 2, 1}. We need to print each combination on a new line, with numbers sorted in ascending order and each number occupying exactly three characters of space. The combina ...
Posted on Thu, 16 Jul 2026 16:27:06 +0000 by NuMan
Remove Duplicates from Sorted Array
Problem Description
Given a non-strictly increasing (sorted with possible duplicates) integer aray nums, remove the duplicates in-place succh that each unique element appears only once. Maintain the relative order of the unique elements and return the number of unique elements in nums.
Let k be the count of unique elements. To pass the test cas ...
Posted on Wed, 15 Jul 2026 16:32:25 +0000 by Zallus
Finding Unique Triplets That Sum to Zero Using Two-Pointer Technique
The three-sum problem requires finding all unique triplets in an array that add up to zero. While depth-first search can solve this after sorting, a more efficient approach uses the two-pointer technique on a sorted array.
Key Points
Use two pointers, not a single pointer—common mistake to avoid
Recommended solving time: 20 minutes
Problem De ...
Posted on Tue, 14 Jul 2026 16:24:10 +0000 by lozza1978
Linked List Algorithms: Pairwise Swapping, Targeted Removal, and Cycle Analysis
Swapping Adjacent Nodes in Pairs
Manipulating node connections uniformly requires a sentinel (dummy) node to eliminate edge cases for the head element. To exchange adjacent pairs, position a reference pointer immediately before the pair undergoing modification.
The iterative approach tracks three critical references: the node preceding the pair ...
Posted on Mon, 13 Jul 2026 17:21:33 +0000 by jon23d
Python Implementation of the Hungarian Algorithm
The Hungarian Algorithm is a classic approach to solve the Maximum Bipartite Matching problem. In a bipartite graph, it identifies the largest set of edges such that each vertex is connected to at most one adjacent vertex.
To illustrate its operation, consider a bipartite graph with left vertices (tasks: A, B, C, D) and right vetrices (workers: ...
Posted on Mon, 13 Jul 2026 16:22:53 +0000 by MichaelHe
Numeric Header Utility Functions in C++
Accumulate Function
The accumulate function performs operations on a sequence:
accumulate(first, last, val, op);
Where first/last are iterators, val is the initial value, and op is the operation (addition, subtraction, etc.).
Example Usage
#include <numeric>
#include <iostream>
#include <vector>
using namespace std;
int main ...
Posted on Sun, 12 Jul 2026 16:24:42 +0000 by wherertheskips
Dynamic Programming Problems
It is clear that S represents the initial magic value, k is the number of selected items, and x is given in the problem.
Noting that x is large but k and n are small, we can define a state that tracks the i-th item, the number of selected items j, and the sum modulo k as l. The goal is to maximize the initial magic value, as higher values reduc ...
Posted on Thu, 09 Jul 2026 17:14:51 +0000 by Virii
Calculating Depth and Node Count in Binary and N-ary Trees
Maximum Depth of a Binary Tree
Given a binary tree, determine its maximum depth - the number of nodes along the longest path from the root node to the farthest leaf node.
Recursive Approach
Using postorder traversal (left-right-root) to calculate node height:
struct TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(i ...
Posted on Tue, 07 Jul 2026 17:24:08 +0000 by AbraCadaver
Dynamic Programming Solutions for House Robber Problems: Linear, Circular, and Tree Variants
House Robber I
The classic house robber problem involves selecting houses to rob such that adjacent houses cannot both be robbed, maximizing total profit.
For each house, there are two choices: rob it or skip it. The decision at each position aims to maximize accumulated wealth.
State Defniition: wealth[i] represents the maximum money obtainabl ...
Posted on Tue, 07 Jul 2026 17:10:21 +0000 by djelica
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