Skip to content
LEETFLIX

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

  1. 5Longest Palindromic SubstringWatch
  2. 11Container With Most WaterWatch
  3. 153SumWatch
  4. 163Sum ClosestWatch
  5. 184SumWatch
  6. 19Remove Nth Node From End of ListWatch
  7. 26Remove Duplicates from Sorted ArrayWatch
  8. 27Remove ElementWatch
  9. 28Find the Index of the First Occurrence in a StringWatch
  10. 31Next PermutationWatch
  11. 42Trapping Rain WaterWatch
  12. 61Rotate ListWatch
  13. 75Sort ColorsWatch
  14. 80Remove Duplicates from Sorted Array IIWatch
  15. 82Remove Duplicates from Sorted List IIWatch
  16. 86Partition ListWatch
  17. 88Merge Sorted ArrayWatch
  18. 125Valid PalindromeWatch
  19. 141Linked List CycleWatch
  20. 142Linked List Cycle IIWatch
  21. 143Reorder ListWatch
  22. 148Sort ListWatch
  23. 151Reverse Words in a StringWatch
  24. 160Intersection of Two Linked ListsWatch
  25. 161One Edit DistanceLocked
  26. 165Compare Version NumbersWatch
  27. 167Two Sum II - Input Array Is SortedWatch
  28. 170Two Sum III - Data structure designLocked
  29. 186Reverse Words in a String IILocked
  30. 189Rotate ArrayWatch
  31. 202Happy NumberWatch
  32. 234Palindrome Linked ListWatch
  33. 244Shortest Word Distance IILocked
  34. 246Strobogrammatic NumberLocked
  35. 251Flatten 2D VectorLocked
  36. 253Meeting Rooms IILocked
  37. 2593Sum SmallerLocked
  38. 272Closest Binary Search Tree Value IILocked
  39. 277Find the CelebrityLocked
  40. 283Move ZeroesWatch
  41. 287Find the Duplicate NumberWatch
  42. 295Find Median from Data StreamWatch
  43. 321Create Maximum NumberWatch
  44. 344Reverse StringWatch
  45. 345Reverse Vowels of a StringWatch
  46. 349Intersection of Two ArraysWatch
  47. 350Intersection of Two Arrays IIWatch
  48. 360Sort Transformed ArrayLocked
  49. 392Is SubsequenceWatch
  50. 408Valid Word AbbreviationLocked
  51. 443String CompressionWatch
  52. 455Assign CookiesWatch
  53. 457Circular Array LoopWatch
  54. 466Count The RepetitionsWatch
  55. 475HeatersWatch
  56. 481Magical StringWatch
  57. 522Longest Uncommon Subsequence IIWatch
  58. 524Longest Word in Dictionary through DeletingWatch
  59. 532K-diff Pairs in an ArrayWatch
  60. 541Reverse String IIWatch
  61. 556Next Greater Element IIIWatch
  62. 557Reverse Words in a String IIIWatch
  63. 567Permutation in StringWatch
  64. 581Shortest Unsorted Continuous SubarrayWatch
  65. 611Valid Triangle NumberWatch
  66. 633Sum of Square NumbersWatch
  67. 647Palindromic SubstringsWatch
  68. 653Two Sum IV - Input is a BSTWatch
  69. 658Find K Closest ElementsWatch
  70. 680Valid Palindrome IIWatch
  71. 696Count Binary SubstringsWatch
  72. 719Find K-th Smallest Pair DistanceWatch
  73. 723Candy CrushLocked
  74. 763Partition LabelsWatch
  75. 777Swap Adjacent in LR StringWatch
  76. 786K-th Smallest Prime FractionWatch
  77. 795Number of Subarrays with Bounded MaximumWatch
  78. 809Expressive WordsWatch
  79. 821Shortest Distance to a CharacterWatch
  80. 825Friends Of Appropriate AgesWatch
  81. 826Most Profit Assigning WorkWatch
  82. 832Flipping an ImageWatch
  83. 838Push DominoesWatch
  84. 844Backspace String CompareWatch
  85. 845Longest Mountain in ArrayWatch
  86. 870Advantage ShuffleWatch
  87. 876Middle of the Linked ListWatch
  88. 881Boats to Save PeopleWatch
  89. 905Sort Array By ParityWatch
  90. 917Reverse Only LettersWatch
  91. 922Sort Array By Parity IIWatch
  92. 9233Sum With MultiplicityWatch
  93. 925Long Pressed NameWatch
  94. 942DI String MatchWatch
  95. 948Bag of TokensWatch
  96. 962Maximum Width RampWatch
  97. 969Pancake SortingWatch
  98. 977Squares of a Sorted ArrayWatch
  99. 986Interval List IntersectionsWatch
  100. 1023Camelcase MatchingWatch
  101. 1048Longest String ChainWatch
  102. 1055Shortest Way to Form StringLocked
  103. 1089Duplicate ZerosWatch
  104. 1099Two Sum Less Than KLocked
  105. 1147Longest Chunked Palindrome DecompositionWatch
  106. 1163Last Substring in Lexicographical OrderWatch
  107. 1214Two Sum BSTsLocked
  108. 1229Meeting SchedulerLocked
  109. 1237Find Positive Integer Solution for a Given EquationWatch
  110. 1265Print Immutable Linked List in ReverseLocked
  111. 1332Remove Palindromic SubsequencesWatch
  112. 1346Check If N and Its Double ExistWatch
  113. 1385Find the Distance Value Between Two ArraysWatch
  114. 1455Check If a Word Occurs As a Prefix of Any Word in a SentenceWatch
  115. 1471The k Strongest Values in an ArrayWatch
  116. 1498Number of Subsequences That Satisfy the Given Sum ConditionWatch
  117. 1508Range Sum of Sorted Subarray SumsWatch
  118. 1537Get the Maximum ScoreWatch
  119. 1570Dot Product of Two Sparse VectorsLocked
  120. 1574Shortest Subarray to be Removed to Make Array SortedWatch
  121. 1577Number of Ways Where Square of Number Is Equal to Product of Two NumbersWatch
  122. 1616Split Two Strings to Make PalindromeWatch
  123. 1634Add Two Polynomials Represented as Linked ListsLocked
  124. 1650Lowest Common Ancestor of a Binary Tree IIILocked
  125. 1679Max Number of K-Sum PairsWatch
  126. 1697Checking Existence of Edge Length Limited PathsWatch
  127. 1712Ways to Split Array Into Three SubarraysWatch
  128. 1721Swapping Nodes in a Linked ListWatch
  129. 1750Minimum Length of String After Deleting Similar EndsWatch
  130. 1754Largest Merge Of Two StringsWatch
  131. 1755Closest Subsequence SumWatch
  132. 1764Form Array by Concatenating Subarrays of Another ArrayWatch
  133. 1768Merge Strings AlternatelyWatch
  134. 1782Count Pairs Of NodesWatch
  135. 1793Maximum Score of a Good SubarrayWatch
  136. 1813Sentence Similarity IIIWatch
  137. 1826Faulty SensorLocked
  138. 1842Next Palindrome Using Same DigitsLocked
  139. 1850Minimum Adjacent Swaps to Reach the Kth Smallest NumberWatch
  140. 1855Maximum Distance Between a Pair of ValuesWatch
  141. 1861Rotating the BoxWatch
  142. 1868Product of Two Run-Length Encoded ArraysLocked
  143. 1877Minimize Maximum Pair Sum in ArrayWatch
  144. 1885Count Pairs in Two ArraysLocked
  145. 1898Maximum Number of Removable CharactersWatch
  146. 1960Maximum Product of the Length of Two Palindromic SubstringsWatch
  147. 1961Check If String Is a Prefix of ArrayWatch
  148. 1963Minimum Number of Swaps to Make the String BalancedWatch
  149. 1989Maximum Number of People That Can Be Caught in TagLocked
  150. 2000Reverse Prefix of WordWatch
  151. 2014Longest Subsequence Repeated k TimesWatch
  152. 2035Partition Array Into Two Arrays to Minimize Sum DifferenceWatch
  153. 2046Sort Linked List Already Sorted Using Absolute ValuesLocked
  154. 2071Maximum Number of Tasks You Can AssignWatch
  155. 2095Delete the Middle Node of a Linked ListWatch
  156. 2105Watering Plants IIWatch
  157. 2108Find First Palindromic String in the ArrayWatch
  158. 2109Adding Spaces to a StringWatch
  159. 2110Number of Smooth Descent Periods of a StockWatch
  160. 2122Recover the Original ArrayWatch
  161. 2130Maximum Twin Sum of a Linked ListWatch
  162. 2149Rearrange Array Elements by SignWatch
  163. 2161Partition Array According to Given PivotWatch
  164. 2193Minimum Number of Moves to Make PalindromeWatch
  165. 2200Find All K-Distant Indices in an ArrayWatch
  166. 2234Maximum Total Beauty of the GardensWatch
  167. 2300Successful Pairs of Spells and PotionsWatch
  168. 2330Valid Palindrome IVLocked
  169. 2332The Latest Time to Catch a BusWatch
  170. 2337Move Pieces to Obtain a StringWatch
  171. 2367Number of Arithmetic TripletsWatch
  172. 2396Strictly Palindromic NumberWatch
  173. 2406Divide Intervals Into Minimum Number of GroupsWatch
  174. 2410Maximum Matching of Players With TrainersWatch
  175. 2422Merge Operations to Turn Array Into a PalindromeLocked
  176. 2441Largest Positive Integer That Exists With Its NegativeWatch
  177. 2460Apply Operations to an ArrayWatch
  178. 2462Total Cost to Hire K WorkersWatch
  179. 2465Number of Distinct AveragesWatch
  180. 2472Maximum Number of Non-overlapping Palindrome SubstringsWatch
  181. 2486Append Characters to String to Make SubsequenceWatch
  182. 2491Divide Players Into Teams of Equal SkillWatch
  183. 2503Maximum Number of Points From Grid QueriesWatch
  184. 2511Maximum Enemy Forts That Can Be CapturedWatch
  185. 2540Minimum Common ValueWatch
  186. 2562Find the Array Concatenation ValueWatch
  187. 2563Count the Number of Fair PairsWatch
  188. 2565Subsequence With the Minimum ScoreWatch
  189. 2570Merge Two 2D Arrays by Summing ValuesWatch
  190. 2576Find the Maximum Number of Marked IndicesWatch
  191. 2592Maximize Greatness of an ArrayWatch
  192. 2604Minimum Time to Eat All GrainsLocked
  193. 2674Split a Circular Linked ListLocked
  194. 2697Lexicographically Smallest PalindromeWatch
  195. 2824Count Pairs Whose Sum is Less than TargetWatch
  196. 2825Make String a Subsequence Using Cyclic IncrementsWatch
  197. 2838Maximum Coins Heroes Can CollectLocked
  198. 2856Minimum Array Length After Pair RemovalsWatch
  199. 2868The Wording GameLocked
  200. 2903Find Indices With Index and Value Difference IWatch
  201. 2905Find Indices With Index and Value Difference IIWatch
  202. 2911Minimum Changes to Make K Semi-palindromesWatch
  203. 2938Separate Black and White BallsWatch
  204. 2970Count the Number of Incremovable Subarrays IWatch
  205. 2972Count the Number of Incremovable Subarrays IIWatch
  206. 3006Find Beautiful Indices in the Given Array IWatch
  207. 3008Find Beautiful Indices in the Given Array IIWatch
  208. 3069Distribute Elements Into Two Arrays IWatch
  209. 3132Find the Integer Added to Array IIWatch
  210. 3186Maximum Total Damage With Spell CastingWatch
  211. 3194Minimum Average of Smallest and Largest ElementsWatch
  212. 3218Minimum Cost for Cutting Cake IWatch
  213. 3239Minimum Number of Flips to Make Binary Grid Palindromic IWatch
  214. 3240Minimum Number of Flips to Make Binary Grid Palindromic IIWatch
  215. 3284Sum of Consecutive SubarraysLocked
  216. 3302Find the Lexicographically Smallest Valid SequenceWatch
  217. 3316Find Maximum Removals From Source StringWatch
  218. 3356Zero Array Transformation IIWatch
  219. 3362Zero Array Transformation IIIWatch
  220. 3400Maximum Number of Matching Indices After Right ShiftsLocked
  221. 3403Find the Lexicographically Largest String From the Box IWatch
  222. 3406Find the Lexicographically Largest String From the Box IILocked
  223. 3455Shortest Matching SubstringWatch
  224. 3460Longest Common Prefix After at Most One RemovalLocked
  225. 3503Longest Palindrome After Substring Concatenation IWatch
  226. 3504Longest Palindrome After Substring Concatenation IIWatch
  227. 3534Path Existence Queries in a Graph IIWatch
  228. 3555Smallest Subarray to Sort in Every Sliding WindowLocked
  229. 3584Maximum Product of First and Last Elements of a SubsequenceWatch
  230. 3633Earliest Finish Time for Land and Water Rides IWatch
  231. 3635Earliest Finish Time for Land and Water Rides IIWatch
  232. 3643Flip Square Submatrix VerticallyWatch
  233. 3645Maximum Total from Optimal Activation OrderWatch
  234. 3649Number of Perfect PairsWatch
  235. 3667Sort Array By Absolute ValueLocked
  236. 3685Subsequence Sum After Capping ElementsWatch
  237. 3722Lexicographically Smallest String After ReverseWatch
  238. 3730Maximum Calories Burnt from JumpsLocked
  239. 3734Lexicographically Smallest Palindromic Permutation Greater Than TargetWatch
  240. 3750Minimum Number of Flips to Reverse Binary StringWatch
  241. 3752Lexicographically Smallest Negated Permutation that Sums to TargetWatch
  242. 3766Minimum Operations to Make Binary PalindromeWatch
  243. 3775Reverse Words With Same Vowel CountWatch
  244. 3794Reverse String PrefixWatch
  245. 3801Minimum Cost to Merge Sorted ListsWatch
  246. 3814Maximum Capacity Within BudgetWatch
  247. 3823Reverse Letters Then Special Characters in a StringWatch
  248. 3844Longest Almost-Palindromic SubstringWatch
  249. 3865Reverse K SubarraysLocked
  250. 3867Sum of GCD of Formed PairsWatch
  251. 3884First Matching Character From Both EndsWatch
  252. 3896Minimum Operations to Transform Array into Alternating PrimeWatch
  253. 3936Minimum Swaps to Move Zeros to EndWatch
  254. 3940Limit Occurrences in Sorted ArrayWatch
  255. 3983Subsequence After One ReplacementWatch
  256. 3991Sort Array Using Prefix ReversalsLocked
  257. 3992Rearrange String to Avoid Character PairWatch
  258. 3998Transform Binary String Using Subsequence SortWatch
  259. 3999Minimum Number of String Groups Through TransformationsWatch
  260. 4001Aggregate Two Time SeriesWatch
  261. 4014Minimum Total Price After Applying DiscountsWatch
  262. 4026Maximum Gap Between StationsWatch
  263. 4030Check ASCII PalindromicWatch