Sliding Window Technique and Spiral Matrix Generation
Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, find the minimal length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists, return 0.
Examples:
Input: target = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: The subarray [4,3] has the minimal lengt ...
Posted on Tue, 16 Jun 2026 17:11:50 +0000 by kusarigama
Solving the Two Sum Problem with Python
The objective is to identify two numbers within an integer array that sum up to a specific target value and return their indices. It is assumed that there is exactly one valid solution per input and that an element cannot be used twice.
For example, given the array nums = [2, 7, 11, 15] and target = 9, the function should return [0, 1] becuase ...
Posted on Tue, 16 Jun 2026 17:01:38 +0000 by ciaranmg
Algorithmic Review and Competition Strategies for NOIP
Contest preparation requires a structured approach to covering fundamental algorithms and optimizing problem-solving strategies. The following outlines core technical topics and execution practices essential for competitive programming.
Core Algorithms and Data Structures
Simulation and Mathematics
High-precision arithmetic is critical for p ...
Posted on Mon, 15 Jun 2026 17:54:23 +0000 by press711
Core Algorithmic Techniques in Java for Competitive Programming
Sorting, searching, dynamic programing, and graph algorithms form the backbone of competitive programming. This article presents a curated list of such patterns, each accompanied by a concise Java implementation. The examples draw inspiration from the ACwing problem set, covering topics from basic sorting to advanced combinatorial mathematics.
...
Posted on Mon, 15 Jun 2026 17:07:00 +0000 by zhaohongli
LeetCode 54: Spiral Matrix and 445: Add Two Numbers II
LeetCode 54: Spiral Matrix
Problem
Given an m x n matrix, return all elements of the matrix in spiral order.
Example 1
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Example 2
Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]
Approach
Traverse from left to right along the top r ...
Posted on Sun, 14 Jun 2026 16:12:36 +0000 by thebusinesslad
Essential Algorithm Templates in C++
Number Theory
Primality Testing via Trial Division
#include <iostream>
using namespace std;
bool isPrime(int num) {
if (num < 2) return false;
for (int d = 2; d <= num / d; ++d)
if (num % d == 0) return false;
return true;
}
int main() {
int queries;
cin >> queries;
while (queries--) {
...
Posted on Sat, 13 Jun 2026 17:12:21 +0000 by sebjlan
Solving the Two Sum Problem in Python
Problem Statement
Given an array of integers, find two distinct indices such that the corresponding elements sum to a specified target value. Each input is guaranteed to have exactly one solution, and elements cannot be reused.
Example: For input array [2, 7, 11, 15] and target 9, return [0, 1] since 2 + 7 = 9.
Solution Approach
A brute-force s ...
Posted on Thu, 11 Jun 2026 18:03:52 +0000 by Helljumper
Mastering Two-Pointer Patterns for Algorithmic Problems
283. Move Zeroes
The objective is to reorganize an array such that all non-zero elements are positioned before any zeros. This operation must be performed in-place without allocating additional space for another array.
Instead of using a secondary buffer, we can utilize a tracking pointer to mark the position where the next non-zero element sho ...
Posted on Thu, 11 Jun 2026 17:56:17 +0000 by coldfused
Core Linked List Manipulation Patterns: Swapping, Removal, and Cycle Detection
Sentinel Node Strategy
A dummy or sentinel node simplifies edge cases where the head pointer might change. By initializing a new node that points to the original head, operations such as deletion or swapping can be treated uniformly with out special casing the start of the list.
auto* sentry = new ListNode(0);
sentry->next = head;
24. Swap ...
Posted on Thu, 11 Jun 2026 17:33:36 +0000 by designguy79
Large Integer Primality Testing and Factorization Algorithms
Miller-Rabin Primality TestThe Miller-Rabin algorithm is a probabilistic method used to determine if a large number is prime. It builds upon Fermat's Little Theorem, which states that for a prime $ p $ and integer $ a $ such that $ 1 \le a < p $, the congruence $ a^{p-1} \equiv 1 \pmod p $ holds. However, relying solely on this theorem allows f ...
Posted on Thu, 11 Jun 2026 16:38:34 +0000 by jl