Solve pair-sum, sliding window, and cycle detection problems with two pointers. Use when reducing O(n²) nested loops to O(n) on sorted or sequential data.
Scanned 9/7/2026
Install to Claude Code
npx -y skills add knoopx/pi --skill two-pointers --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Two Pointers?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/knoopx-two-pointers)More formats (shields.io, HTML) on the badges page.
---
name: two-pointers
description: "Solve pair-sum, sliding window, and cycle detection problems with two pointers. Use when reducing O(n²) nested loops to O(n) on sorted or sequential data."
topic: Two Pointers and Sliding Window
token_cost: 100
related: [binary-search, sorting-choice, hash-vs-tree]
keywords:
[
pointer,
two,
sliding,
window,
substring,
subarray,
pair,
sum,
target,
sorted,
left,
right,
fast,
slow,
cycle,
linked,
list,
contiguous,
consecutive,
squeeze,
]
---
## When to use
Two pointers on a sorted array: start left=0, right=n-1, move inward based on comparison.
## Rules
- Solves pair-sum, three-sum, container problems in O(n)
- Sliding window: expand right boundary, shrink left when constraint violated
- Solves "longest/shortest substring with property" in O(n)
- Fast/slow pointers: detect cycles in linked lists (Floyd's), find middle element
- If brute force is O(n^2) nested loops over a sorted or sequential structure, two pointers likely reduces it to O(n)
- ALWAYS prefer two pointers over nested loops when data is sorted
- NEVER use nested loops when two pointers would work
## Complexity
Two pointers: O(n). Sliding window: O(n). Fast/slow: O(n).
## Example
"Two sum on sorted" → `left=0, right=n-1`; if `arr[left]+arr[right] < target`: left++, else right--. "Longest substring without repeats" → expand right, shrink left when duplicate found.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!
Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.
Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...
Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.
Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.
A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling