method
Two Pointers — animated LeetCode walkthroughs
LeetCode problems solved with Two Pointers. Browse the complete tag, then watch the algorithm move — step-by-step animation, Python and Go.
263 problems · 221 animated · 42 locked
Start with a walkthrough
Full Two pointers index
- 5Longest Palindromic SubstringWatch
- 11Container With Most WaterWatch
- 153SumWatch
- 163Sum ClosestWatch
- 184SumWatch
- 19Remove Nth Node From End of ListWatch
- 26Remove Duplicates from Sorted ArrayWatch
- 27Remove ElementWatch
- 28Find the Index of the First Occurrence in a StringWatch
- 31Next PermutationWatch
- 42Trapping Rain WaterWatch
- 61Rotate ListWatch
- 75Sort ColorsWatch
- 80Remove Duplicates from Sorted Array IIWatch
- 82Remove Duplicates from Sorted List IIWatch
- 86Partition ListWatch
- 88Merge Sorted ArrayWatch
- 125Valid PalindromeWatch
- 141Linked List CycleWatch
- 142Linked List Cycle IIWatch
- 143Reorder ListWatch
- 148Sort ListWatch
- 151Reverse Words in a StringWatch
- 160Intersection of Two Linked ListsWatch
- 161One Edit DistanceLocked
- 165Compare Version NumbersWatch
- 167Two Sum II - Input Array Is SortedWatch
- 170Two Sum III - Data structure designLocked
- 186Reverse Words in a String IILocked
- 189Rotate ArrayWatch
- 202Happy NumberWatch
- 234Palindrome Linked ListWatch
- 244Shortest Word Distance IILocked
- 246Strobogrammatic NumberLocked
- 251Flatten 2D VectorLocked
- 253Meeting Rooms IILocked
- 2593Sum SmallerLocked
- 272Closest Binary Search Tree Value IILocked
- 277Find the CelebrityLocked
- 283Move ZeroesWatch
- 287Find the Duplicate NumberWatch
- 295Find Median from Data StreamWatch
- 321Create Maximum NumberWatch
- 344Reverse StringWatch
- 345Reverse Vowels of a StringWatch
- 349Intersection of Two ArraysWatch
- 350Intersection of Two Arrays IIWatch
- 360Sort Transformed ArrayLocked
- 392Is SubsequenceWatch
- 408Valid Word AbbreviationLocked
- 443String CompressionWatch
- 455Assign CookiesWatch
- 457Circular Array LoopWatch
- 466Count The RepetitionsWatch
- 475HeatersWatch
- 481Magical StringWatch
- 522Longest Uncommon Subsequence IIWatch
- 524Longest Word in Dictionary through DeletingWatch
- 532K-diff Pairs in an ArrayWatch
- 541Reverse String IIWatch
- 556Next Greater Element IIIWatch
- 557Reverse Words in a String IIIWatch
- 567Permutation in StringWatch
- 581Shortest Unsorted Continuous SubarrayWatch
- 611Valid Triangle NumberWatch
- 633Sum of Square NumbersWatch
- 647Palindromic SubstringsWatch
- 653Two Sum IV - Input is a BSTWatch
- 658Find K Closest ElementsWatch
- 680Valid Palindrome IIWatch
- 696Count Binary SubstringsWatch
- 719Find K-th Smallest Pair DistanceWatch
- 723Candy CrushLocked
- 763Partition LabelsWatch
- 777Swap Adjacent in LR StringWatch
- 786K-th Smallest Prime FractionWatch
- 795Number of Subarrays with Bounded MaximumWatch
- 809Expressive WordsWatch
- 821Shortest Distance to a CharacterWatch
- 825Friends Of Appropriate AgesWatch
- 826Most Profit Assigning WorkWatch
- 832Flipping an ImageWatch
- 838Push DominoesWatch
- 844Backspace String CompareWatch
- 845Longest Mountain in ArrayWatch
- 870Advantage ShuffleWatch
- 876Middle of the Linked ListWatch
- 881Boats to Save PeopleWatch
- 905Sort Array By ParityWatch
- 917Reverse Only LettersWatch
- 922Sort Array By Parity IIWatch
- 9233Sum With MultiplicityWatch
- 925Long Pressed NameWatch
- 942DI String MatchWatch
- 948Bag of TokensWatch
- 962Maximum Width RampWatch
- 969Pancake SortingWatch
- 977Squares of a Sorted ArrayWatch
- 986Interval List IntersectionsWatch
- 1023Camelcase MatchingWatch
- 1048Longest String ChainWatch
- 1055Shortest Way to Form StringLocked
- 1089Duplicate ZerosWatch
- 1099Two Sum Less Than KLocked
- 1147Longest Chunked Palindrome DecompositionWatch
- 1163Last Substring in Lexicographical OrderWatch
- 1214Two Sum BSTsLocked
- 1229Meeting SchedulerLocked
- 1237Find Positive Integer Solution for a Given EquationWatch
- 1265Print Immutable Linked List in ReverseLocked
- 1332Remove Palindromic SubsequencesWatch
- 1346Check If N and Its Double ExistWatch
- 1385Find the Distance Value Between Two ArraysWatch
- 1455Check If a Word Occurs As a Prefix of Any Word in a SentenceWatch
- 1471The k Strongest Values in an ArrayWatch
- 1498Number of Subsequences That Satisfy the Given Sum ConditionWatch
- 1508Range Sum of Sorted Subarray SumsWatch
- 1537Get the Maximum ScoreWatch
- 1570Dot Product of Two Sparse VectorsLocked
- 1574Shortest Subarray to be Removed to Make Array SortedWatch
- 1577Number of Ways Where Square of Number Is Equal to Product of Two NumbersWatch
- 1616Split Two Strings to Make PalindromeWatch
- 1634Add Two Polynomials Represented as Linked ListsLocked
- 1650Lowest Common Ancestor of a Binary Tree IIILocked
- 1679Max Number of K-Sum PairsWatch
- 1697Checking Existence of Edge Length Limited PathsWatch
- 1712Ways to Split Array Into Three SubarraysWatch
- 1721Swapping Nodes in a Linked ListWatch
- 1750Minimum Length of String After Deleting Similar EndsWatch
- 1754Largest Merge Of Two StringsWatch
- 1755Closest Subsequence SumWatch
- 1764Form Array by Concatenating Subarrays of Another ArrayWatch
- 1768Merge Strings AlternatelyWatch
- 1782Count Pairs Of NodesWatch
- 1793Maximum Score of a Good SubarrayWatch
- 1813Sentence Similarity IIIWatch
- 1826Faulty SensorLocked
- 1842Next Palindrome Using Same DigitsLocked
- 1850Minimum Adjacent Swaps to Reach the Kth Smallest NumberWatch
- 1855Maximum Distance Between a Pair of ValuesWatch
- 1861Rotating the BoxWatch
- 1868Product of Two Run-Length Encoded ArraysLocked
- 1877Minimize Maximum Pair Sum in ArrayWatch
- 1885Count Pairs in Two ArraysLocked
- 1898Maximum Number of Removable CharactersWatch
- 1960Maximum Product of the Length of Two Palindromic SubstringsWatch
- 1961Check If String Is a Prefix of ArrayWatch
- 1963Minimum Number of Swaps to Make the String BalancedWatch
- 1989Maximum Number of People That Can Be Caught in TagLocked
- 2000Reverse Prefix of WordWatch
- 2014Longest Subsequence Repeated k TimesWatch
- 2035Partition Array Into Two Arrays to Minimize Sum DifferenceWatch
- 2046Sort Linked List Already Sorted Using Absolute ValuesLocked
- 2071Maximum Number of Tasks You Can AssignWatch
- 2095Delete the Middle Node of a Linked ListWatch
- 2105Watering Plants IIWatch
- 2108Find First Palindromic String in the ArrayWatch
- 2109Adding Spaces to a StringWatch
- 2110Number of Smooth Descent Periods of a StockWatch
- 2122Recover the Original ArrayWatch
- 2130Maximum Twin Sum of a Linked ListWatch
- 2149Rearrange Array Elements by SignWatch
- 2161Partition Array According to Given PivotWatch
- 2193Minimum Number of Moves to Make PalindromeWatch
- 2200Find All K-Distant Indices in an ArrayWatch
- 2234Maximum Total Beauty of the GardensWatch
- 2300Successful Pairs of Spells and PotionsWatch
- 2330Valid Palindrome IVLocked
- 2332The Latest Time to Catch a BusWatch
- 2337Move Pieces to Obtain a StringWatch
- 2367Number of Arithmetic TripletsWatch
- 2396Strictly Palindromic NumberWatch
- 2406Divide Intervals Into Minimum Number of GroupsWatch
- 2410Maximum Matching of Players With TrainersWatch
- 2422Merge Operations to Turn Array Into a PalindromeLocked
- 2441Largest Positive Integer That Exists With Its NegativeWatch
- 2460Apply Operations to an ArrayWatch
- 2462Total Cost to Hire K WorkersWatch
- 2465Number of Distinct AveragesWatch
- 2472Maximum Number of Non-overlapping Palindrome SubstringsWatch
- 2486Append Characters to String to Make SubsequenceWatch
- 2491Divide Players Into Teams of Equal SkillWatch
- 2503Maximum Number of Points From Grid QueriesWatch
- 2511Maximum Enemy Forts That Can Be CapturedWatch
- 2540Minimum Common ValueWatch
- 2562Find the Array Concatenation ValueWatch
- 2563Count the Number of Fair PairsWatch
- 2565Subsequence With the Minimum ScoreWatch
- 2570Merge Two 2D Arrays by Summing ValuesWatch
- 2576Find the Maximum Number of Marked IndicesWatch
- 2592Maximize Greatness of an ArrayWatch
- 2604Minimum Time to Eat All GrainsLocked
- 2674Split a Circular Linked ListLocked
- 2697Lexicographically Smallest PalindromeWatch
- 2824Count Pairs Whose Sum is Less than TargetWatch
- 2825Make String a Subsequence Using Cyclic IncrementsWatch
- 2838Maximum Coins Heroes Can CollectLocked
- 2856Minimum Array Length After Pair RemovalsWatch
- 2868The Wording GameLocked
- 2903Find Indices With Index and Value Difference IWatch
- 2905Find Indices With Index and Value Difference IIWatch
- 2911Minimum Changes to Make K Semi-palindromesWatch
- 2938Separate Black and White BallsWatch
- 2970Count the Number of Incremovable Subarrays IWatch
- 2972Count the Number of Incremovable Subarrays IIWatch
- 3006Find Beautiful Indices in the Given Array IWatch
- 3008Find Beautiful Indices in the Given Array IIWatch
- 3069Distribute Elements Into Two Arrays IWatch
- 3132Find the Integer Added to Array IIWatch
- 3186Maximum Total Damage With Spell CastingWatch
- 3194Minimum Average of Smallest and Largest ElementsWatch
- 3218Minimum Cost for Cutting Cake IWatch
- 3239Minimum Number of Flips to Make Binary Grid Palindromic IWatch
- 3240Minimum Number of Flips to Make Binary Grid Palindromic IIWatch
- 3284Sum of Consecutive SubarraysLocked
- 3302Find the Lexicographically Smallest Valid SequenceWatch
- 3316Find Maximum Removals From Source StringWatch
- 3356Zero Array Transformation IIWatch
- 3362Zero Array Transformation IIIWatch
- 3400Maximum Number of Matching Indices After Right ShiftsLocked
- 3403Find the Lexicographically Largest String From the Box IWatch
- 3406Find the Lexicographically Largest String From the Box IILocked
- 3455Shortest Matching SubstringWatch
- 3460Longest Common Prefix After at Most One RemovalLocked
- 3503Longest Palindrome After Substring Concatenation IWatch
- 3504Longest Palindrome After Substring Concatenation IIWatch
- 3534Path Existence Queries in a Graph IIWatch
- 3555Smallest Subarray to Sort in Every Sliding WindowLocked
- 3584Maximum Product of First and Last Elements of a SubsequenceWatch
- 3633Earliest Finish Time for Land and Water Rides IWatch
- 3635Earliest Finish Time for Land and Water Rides IIWatch
- 3643Flip Square Submatrix VerticallyWatch
- 3645Maximum Total from Optimal Activation OrderWatch
- 3649Number of Perfect PairsWatch
- 3667Sort Array By Absolute ValueLocked
- 3685Subsequence Sum After Capping ElementsWatch
- 3722Lexicographically Smallest String After ReverseWatch
- 3730Maximum Calories Burnt from JumpsLocked
- 3734Lexicographically Smallest Palindromic Permutation Greater Than TargetWatch
- 3750Minimum Number of Flips to Reverse Binary StringWatch
- 3752Lexicographically Smallest Negated Permutation that Sums to TargetWatch
- 3766Minimum Operations to Make Binary PalindromeWatch
- 3775Reverse Words With Same Vowel CountWatch
- 3794Reverse String PrefixWatch
- 3801Minimum Cost to Merge Sorted ListsWatch
- 3814Maximum Capacity Within BudgetWatch
- 3823Reverse Letters Then Special Characters in a StringWatch
- 3844Longest Almost-Palindromic SubstringWatch
- 3865Reverse K SubarraysLocked
- 3867Sum of GCD of Formed PairsWatch
- 3884First Matching Character From Both EndsWatch
- 3896Minimum Operations to Transform Array into Alternating PrimeWatch
- 3936Minimum Swaps to Move Zeros to EndWatch
- 3940Limit Occurrences in Sorted ArrayWatch
- 3983Subsequence After One ReplacementWatch
- 3991Sort Array Using Prefix ReversalsLocked
- 3992Rearrange String to Avoid Character PairWatch
- 3998Transform Binary String Using Subsequence SortWatch
- 3999Minimum Number of String Groups Through TransformationsWatch
- 4001Aggregate Two Time SeriesWatch
- 4014Minimum Total Price After Applying DiscountsWatch
- 4026Maximum Gap Between StationsWatch
- 4030Check ASCII PalindromicWatch