Two-Pointer Techniques for Array Manipulation Algorithms
In-Place Element Removal
When tasked with filtering out specific values from an array in-place, allocating additional memory is often restricted. The two-pointer method provides an elegant solution by separating the reading and writing processes.
Strategy: Read and Write Pointers
We initialize two distinct indices: a write_idx to track the posi ...
Posted on Mon, 21 Sep 2026 16:38:55 +0000 by jacobelias
Optimizing In-Place Zero Duplication Using a Two-Pass Two-Pointer Technique
Problem Definition
Given a fixed-length array of integers, the objective is to duplicate every occurrence of the value zero. When a zero is duplicated, all subsequent elements must be shifted one position to the right. Any values that would extend beyond the original array boundaries are discarded. The transformation must be executed directly w ...
Posted on Sat, 22 Aug 2026 16:22:53 +0000 by lorddraco98
Algorithm Problem Solutions: Snowflakes, Sequences, and Graph Theory
Problem 1: Unique Snowflake Collection
Problem Statement: At n different times, snowflakes of various shapes fall (represented by distinct integers). We want to collect snowflakes from time a to time b such that no duplicate shapes are collected, and the total number of snowflakes collected is maximized.
Solution Approach: Two Pointers Techniqu ...
Posted on Thu, 06 Aug 2026 16:35:07 +0000 by mispris006
Detecting Cycles and Removing k-th From End Using Two-Pointer Techniques
Given a singly linked list, determine weather it contains a cycle. Return true if a cycle exists; otherwise, return false. The solution must use O(1) auxiliary space.
This problem is classically solved using Floyd’s Cycle Detection Algorrithm — also known as the "tortoise and hare" approach. Two pointers traverse the list at different ...
Posted on Mon, 20 Jul 2026 16:57:01 +0000 by christian_phpbeginner
Sliding Window Technique: Core Patterns and Example Problems
This article provides a concise summary of sliding window templates followed by practical examples. The recommended reading approach: skim the summary first, then study how each template is applied in the examples, and finally revisit the summary to solidify your understanding.
Summary
Problems that are well-suited for the sliding window techni ...
Posted on Sun, 19 Jul 2026 16:06:33 +0000 by wenxi
Removing Elements from Arrays In-Place: LeetCode Problem 27 Analysis
Problem Understanding
The challenge requires removing specific values from an array while meeting these constraints:
Use only O(1) additional space and modify the input array in-place
Element ordering can be changed
Focus only on elements within the new length boundary
The solution will be validated using code similar to:
int result_length = ...
Posted on Tue, 14 Jul 2026 16:26:28 +0000 by draco2317
LeetCode Problem 160: Intersection of Linked Lists
Intersection of Linked Lists
Problem Link
LeetCode 160
Problem Statement
Given the heads of two singly linked lists, headA and headB, return the node at which the two lists intesrect. If there is no intersection, return nullptr.
The linked lists must retain their original structure after the function returns. You are not allowed to modify th ...
Posted on Sun, 05 Jul 2026 16:14:54 +0000 by bobthebullet990
Hash Table Algorithms: Solving Multi-Sum Problems
Hash Table Algorithms: Solving Multi-Sum Problems
4Sum II (LeetCode 454)
Problem Description
Given four integer arrays nums1, nums2, nums3, and nums4, all of length n, return the number of tuples (i, j, k, l) such that:
0 <= i, j, k, l < n
nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
Example 1:
Input: nums1 = [1,2], nums2 = [-2,-1 ...
Posted on Mon, 22 Jun 2026 16:42:09 +0000 by sanlove
Linked List Operations: Swapping Nodes, Removing Nth Node, Finding Intersections, and Detecting Cycles
Pairwise Node Swapping
To swap adjacent nodes in pairs, we utilize a dummy node to simplify edge cases. The core idea involves manipulating pointers to reverse each pair while maintaining proper linkage with the rest of the list. A cursor pointer tracks the predecessor of each pair being processed.
The termination condition varies based on whet ...
Posted on Sat, 20 Jun 2026 16:35:52 +0000 by matt6805
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