Where to Find Visualizations of the Two-Pointer Technique in LeetCodeAnimation

The LeetCodeAnimation repository stores two-pointer visualizations as GIF files inside each problem's Animation subdirectory, embedded within corresponding markdown articles in the Article folder.

The MisterBooo/LeetCodeAnimation open-source project provides animated walkthroughs of LeetCode solutions, including comprehensive visualizations of the two-pointer technique. These visual assets accompany Java, Python, and JavaScript implementations to demonstrate how left-right pointers converge or diverge across sorted arrays and strings.

Locating Two-Pointer Visualizations in the Repository Structure

The repository organizes each LeetCode problem into dedicated directories containing algorithm explanations, source code, and animated visualizations. For two-pointer problems, the animations specifically illustrate pointer movement patterns—such as collision pointers moving inward from both ends or fast-slow pointers traversing at different speeds.

Problem #11: Container With Most Water

The visualization for this classic two-pointer problem is located at 0011-maxArea/Animation/maxArea.gif. This GIF demonstrates the left-right pointer scan that calculates the maximum water container area by comparing heights and converging toward the center. The accompanying article at 0011-maxArea/Article/0011-maxArea.md provides the Java implementation and embeds the animation directly within the explanation.

Problem #167: Two Sum II – Input Array Is Sorted

For the collision pointer technique (碰撞指针), the repository provides 0167-Two-Sum-II-Input-array-is-sorted/Animation/Animation.gif. This visualization shows two pointers starting at opposite ends of a sorted array and moving inward until they find the target sum. The full explanation and Python implementation reside in 0167-Two-Sum-II-Input-array-is-sorted/Article/0167-Two-Sum-II-Input-array-is-sorted.md.

Additional Two-Pointer Problems in the Notes Directory

Beyond the dedicated problem folders, the notes/ directory contains supplementary visualizations for several two-pointer algorithms:

  • LeetCode #3 – Longest Substring Without Repeating Characters: Uses sliding-window combined with two-pointer logic, documented in notes/LeetCode第3号问题:无重复字符的最长子串.md with embedded GIFs showing window expansion and contraction.
  • LeetCode #15 – 3Sum: Demonstrates the outer loop with inner left-right pointers on a sorted array, available in notes/LeetCode第15号问题:三数之和.md.
  • LeetCode #283 – Move Zeroes: Illustrates the fast-slow pointer technique for in-place array compaction, found in notes/LeetCode第283号问题:移动零.md.

Code Implementation Examples

The following implementations demonstrate the two-pointer patterns visualized in the repository animations.

Container With Most Water (Problem #11) – Java

public int maxArea(int[] height) {
    int left = 0;                         // left pointer
    int right = height.length - 1;         // right pointer
    int max = 0;
    while (left < right) {
        // compute area with current pointers
        int area = Math.min(height[left], height[right]) * (right - left);
        max = Math.max(max, area);
        // move the pointer pointing to the shorter line
        if (height[left] < height[right]) left++;
        else right--;
    }
    return max;
}

Source: 0011-maxArea/Article/0011-maxArea.md

Two Sum II – Sorted Array (Problem #167) – Python

class Solution(object):
    def twoSum(self, numbers, target):
        left, right = 0, len(numbers) - 1
        while left <= right:
            s = numbers[left] + numbers[right]
            if s == target:
                return [left + 1, right + 1]   # 1-based indices

            elif s > target:
                right -= 1
            else:
                left += 1
        return [-1, -1]

Source: 0167-Two-Sum-II-Input-array-is-sorted/Article/0167-Two-Sum-II-Input-array-is-sorted.md

3Sum (Problem #15) – JavaScript

function threeSum(nums) {
    nums.sort((a, b) => a - b);
    const res = [];
    for (let i = 0; i < nums.length - 2; i++) {
        if (i > 0 && nums[i] === nums[i - 1]) continue; // skip dup
        let left = i + 1, right = nums.length - 1;
        while (left < right) {
            const sum = nums[i] + nums[left] + nums[right];
            if (sum === 0) {
                res.push([nums[i], nums[left], nums[right]]);
                while (nums[left] === nums[++left]);   // skip dup
                while (nums[right] === nums[--right]); // skip dup
            } else if (sum < 0) left++;
            else right--;
        }
    }
    return res;
}

Source: notes/LeetCode第15号问题:三数之和.md

Summary

  • Two-pointer visualizations in LeetCodeAnimation are stored as GIF files within each problem's Animation subdirectory.
  • Problem #11 (Container With Most Water) and Problem #167 (Two Sum II) provide canonical examples of collision pointer animations.
  • The notes/ directory contains additional two-pointer visualizations for problems like 3Sum, Move Zeroes, and Longest Substring Without Repeating Characters.
  • Each visualization is embedded in markdown articles located in the Article folder alongside Java, Python, or JavaScript implementations.

Frequently Asked Questions

What file format are the two-pointer visualizations stored in?

The animations are saved as GIF files (e.g., maxArea.gif, Animation.gif) within each problem's Animation folder. These GIFs loop continuously to demonstrate pointer movement patterns such as collision pointers converging from both ends or fast-slow pointers traversing at different speeds.

How do I access the two-pointer animations on GitHub?

Navigate to the specific problem directory (such as 0011-maxArea/ or 0167-Two-Sum-II-Input-array-is-sorted/), then open the Animation subdirectory. Alternatively, view the embedded animations directly in the markdown articles stored in the Article folder, where the GIFs are referenced using standard markdown image syntax.

What is the difference between collision pointers and the two-pointer technique?

According to the LeetCodeAnimation repository, "collision pointers" (碰撞指针) refer to the specific two-pointer pattern where one pointer starts at the beginning and another at the end of a sorted array, moving toward each other until they meet. This is a subset of the general two-pointer technique, which also includes fast-slow pointer patterns used for in-place array manipulation or cycle detection.

Are there visualizations for the fast-slow pointer technique?

Yes. The repository includes animations for the fast-slow pointer pattern (also called the "tortoise and hare" method) in notes/LeetCode第283号问题:移动零.md, which demonstrates in-place array compaction by moving non-zero elements to the front using two pointers moving at different speeds. This technique is also visualized in the sliding-window implementations within the notes directory.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →