LeetCode Two Pointer Patterns: The Complete Guide
Master every two pointer pattern for LeetCode: opposite-end, same-direction, and fast/slow pointers with templates, complexity analysis, and 15+ mapped problems.
33 posts · page 1 of 1
Master every two pointer pattern for LeetCode: opposite-end, same-direction, and fast/slow pointers with templates, complexity analysis, and 15+ mapped problems.
Master advanced prefix sum techniques — 2D prefix sums for submatrix queries, difference arrays for range updates in O(1), subarray sum divisible by K, XOR prefix, and more.
Master matrix traversal patterns — spiral order, diagonal traversal, zigzag, boundary traversal, matrix rotation, transpose, search in 2D matrix, and set matrix zeroes with Python.
Master subarray sum techniques — prefix sum for range queries, Kadane's algorithm for maximum subarray, hash map for subarray sum equals K, sliding window, and maximum product subarray.
Master binary search patterns for LeetCode including search space reduction, boundary finding, rotated array search, and practical templates.
Understand the real difference between arrays and slices in Go, how slice headers work, and how to avoid the classic aliasing and capacity surprises.
Solve the multi-transaction stock problem with the greedy peak-valley insight: sum every positive daily delta. Includes complexity analysis and DP alternative.
Solve Capacity to Ship Packages Within D Days by binary searching the ship capacity. Includes feasibility check, tight bounds, and a worked example.
A clear walkthrough of the Contains Duplicate problem, covering brute force, sorting, and the optimal hash set approach with complexity analysis.
Solve Find Peak Element in O(log n) by binary searching on the slope direction. Includes diagram and edge cases.
Solve Koko Eating Bananas by binary searching the eating speed. Includes the monotonic predicate, ceiling division, and complexity.
Solve Majority Element in O(n) time and O(1) space using Boyer-Moore majority vote. Includes intuition, walkthrough, and edge cases.
Solve the Missing Number problem with three approaches: hashing, Gauss sum formula, and XOR. Includes complexity analysis and interview tips.
Solve Move Zeroes in O(n) time and O(1) space using a write pointer. Includes walkthrough, edge cases, and interview tips.
Build Pascal's Triangle in O(n^2) time using simple row-by-row addition. Includes a clear diagram, edge cases, and complexity analysis.
Add one to a big integer stored as a digit array by walking from the back. Includes carry handling, the all-nines edge case, and complexity analysis.
Solve Remove Duplicates from Sorted Array in O(n) time and O(1) space with the two-pointer write-pointer pattern. Includes walkthrough, edge cases, and complexity.
Solve Set Matrix Zeroes in place using the first row and column as markers. Includes a step-by-step walkthrough and edge cases.
Solve the Single Number problem in O(n) time and O(1) space using XOR. Includes a walkthrough, edge cases, and follow-up variants.
Solve Find Minimum in Rotated Sorted Array in logarithmic time with a modified binary search. Learn the pivot-finding invariant, edge cases, and how to extend the pattern to related problems.
Solve Maximum Product Subarray in linear time by tracking running min and max. Learn why negative numbers flip the role of min and max and see clean code.
Solve the Reverse String problem in place using the two-pointer technique. Walkthrough, complexity analysis, edge cases, and clean Java, Python, and C++ implementations.
Rotate an array by k steps in O(1) extra space using the triple-reverse trick. Compare it with the extra-array approach and learn why this pattern keeps showing up.
Master the three most powerful array methods in JavaScript — map, filter, and reduce — with practical examples, chaining patterns, and performance tips.
Walk through Best Time to Buy and Sell Stock. We go from the quadratic brute force to a clean one-pass solution tracking the running minimum.
A clear walkthrough of Maximum Subarray. We build Kadane's algorithm from first principles and contrast it with the divide and conquer approach.
Solve Product of Array Except Self in O(n) without division using prefix and suffix passes. Clean walkthrough plus interview script.
Rotate an n by n matrix 90 degrees in place by transposing and reversing each row. Walkthrough, edge cases, complexity, and interview script.
Solve Spiral Matrix with the four-boundary walk pattern. Clean implementation, edge cases for rectangles, complexity, and interview tips.
The everyday array patterns every DSA learner should know — traversal, linear search, insertion, deletion, reversal, rotation, prefix sums, Kadane's preview, and the one-pass habit.
A beginner's introduction to arrays — contiguous memory, indexing, the Python list vs C array caveat, time complexity of read/write/insert/delete, and 1D vs 2D arrays.
Ten classic array interview problems with examples, approach, complexity, and clean Python solutions — Two Sum, Best Time to Buy/Sell Stock, Kadane's, Rotate Array, Product Except Self, and more.
A complete beginner's guide to JavaScript arrays — creation, indexing, the essential mutation methods, iteration, map/filter/reduce, and a first look at spread and destructuring.