Two Pointers Pattern

Use two indices moving through a sequence to find pairs, remove elements, or partition.

#Title
153 Sum
163 Sum Closest
184 Sum
19Remove Nth Node From End of List
26Remove Duplicates from Sorted Array
80Remove Duplicates from Sorted Array II
86Partition List
141Linked List Cycle
142Linked List Cycle II
143Reorder List
167Two Sum II - Input array is sorted
2593Sum Smaller
283Move Zeroes
287Find the Duplicate Number
344Reverse String
345Reverse Vowels of a String
356Line Reflection
360Sort Transformed Array
369Plus One Linked List
457Circular Array Loop
567Permutation in String
611Valid Triangle Number
653Two Sum IV - Input is a BST
777Swap Adjacent in LR String
826Most Profit Assigning Work
828Count Unique Characters of All Substrings of a Given String
844Backspace String Compare
876Middle of the Linked List
948Bag of Tokens
977Squares of a Sorted Array
992Subarrays with K Different Integers
1033Moving Stones Until Consecutive
1040Moving Stones Until Consecutive II
1213Intersection of Three Sorted Arrays
1234Replace the Substring for Balanced String
1248Count Number of Nice Subarrays
1385Find the Distance Value Between Two Arrays
1498Number of Subsequences That Satisfy the Given Sum Condition
1508Range Sum of Sorted Subarray Sums
1521Find a Value of a Mysterious Function Closest to Target
1604Alert Using Same Key-Card Three or More Times in a One Hour Period
1610Maximum Number of Visible Points
1616Split Two Strings to Make Palindrome
1658Minimum Operations to Reduce X to Zero
1687Delivering Boxes from Storage to Ports
1695Maximum Erasure Value
1712Ways to Split Array Into Three Subarrays
1750Minimum Length of String After Deleting Similar Ends
1782Count Pairs Of Nodes
1838Frequency of the Most Frequent Element
1852Distinct Numbers in Each Subarray
1855Maximum Distance Between a Pair of Values
1868Product of Two Run-Length Encoded Arrays
1885Count Pairs in Two Arrays
1888Minimum Number of Flips to Make the Binary String Alternatings
1984Minimum Difference Between Highest and Lowest of K Scores
1989Maximum Number of People That Can Be Caught in Tag
2009Minimum Number of Operations to Make Array Continuous
2040Kth Smallest Product of Two Sorted Arrays
2095Delete the Middle Node of a Linked List
2105Watering Plants II
2130Maximum Twin Sum of a Linked List
2149Rearrange Array Elements by Sign
2161Partition Array According to Given Pivot
2181Merge Nodes in Between Zeros
2200Find All K-Distant Indices in an Array
2234Maximum Total Beauty of the Gardens
2302Count Subarrays With Score Less Than K
2330Valid Palindrome IV
2332The Latest Time to Catch a Bus
2337Move Pieces to Obtain a String
2348Number of Zero-Filled Subarrays
2354Number of Excellent Pairs
2393Count Strictly Increasing Subarrays
2398Maximum Number of Robots Within Budget
2401Longest Nice Subarray
2422Merge Operations to Turn Array Into a Palindrome
2426Number of Pairs Satisfying Inequality
2444Count Subarrays With Fixed Bounds
2461Maximum Sum of Distinct Subarrays With Length K
2462Total Cost to Hire K Workers
2465Number of Distinct Averages
2472Maximum Number of Non-overlapping Palindrome Substrings
2486Append Characters to String to Make Subsequence
2511Maximum Enemy Forts That Can Be Captured
2516Take K of Each Character From Left and Right
2524Maximum Frequency Score of a Subarray
2537Count the Number of Good Subarrays
2540Minimum Common Value
2555Maximize Win From Two Segments
2563Count the Number of Fair Pairs
2565Subsequence With the Minimum Score
2570Merge Two 2D Arrays by Summing Values
2576Find the Maximum Number of Marked Indices
2592Maximize Greatness of an Array
2609Find the Longest Balanced Substring of a Binary String
2653Sliding Subarray Beauty
2674Split a Circular Linked List
2722Join Two Arrays by ID
2730Find the Longest Semi-Repetitive Substring
2743Count Substrings Without Repeating Character
2747Count Zero Request Servers
2762Continuous Subarrays
2763Sum of Imbalance Numbers of All Subarrays
2779Maximum Beauty of an Array After Applying Operation
2781Length of the Longest Valid Substring
2799Count Complete Subarrays in an Array
2824Count Pairs Whose Sum is Less than Target
2825Make String a Subsequence Using Cyclic Increments
2831Find the Longest Equal Subarray
2836Maximize Value of Function in a Ball Passing Game
2838Maximum Coins Heroes Can Collect
2841Maximum Sum of Almost Unique Subarray
2875Minimum Size Subarray in Infinite Array
2904Shortest and Lexicographically Smallest Beautiful String
2932Maximum Strong Pair XOR I
2933High-Access Employees
2935Maximum Strong Pair XOR II
2938Separate Black and White Balls
2945Find Maximum Non-decreasing Array Length
2953Count Complete Substrings
2958Length of Longest Subarray With at Most K Frequency
2962Count Subarrays Where Max Element Appears at Least K Times
2968Apply Operations to Maximize Frequency Score
2970Count the Number of Incremovable Subarrays I
2972Count the Number of Incremovable Subarrays II
3006Find Beautiful Indices in the Given Array I
3008Find Beautiful Indices in the Given Array II
3085Minimum Deletions to Make String K-Special
3088Make String Anti-palindrome
3090Maximum Length Substring With Two Occurrences
3095Shortest Subarray With OR at Least K I
3097Shortest Subarray With OR at Least K II
3098Find the Sum of Subsequence Powers
3104Find Longest Self-Contained Substring
3117Minimum Sum of Values by Dividing Array
3134Find the Median of the Uniqueness Array
3171Find Subarray With Bitwise OR Closest to K
3174Clear Digits
3186Maximum Total Damage With Spell Casting
3193Count the Number of Inversions
3206Alternating Groups I
3208Alternating Groups II
3234Count the Number of Substrings With Dominant Ones
3254Find the Power of K-Size Subarrays I
3255Find the Power of K-Size Subarrays II
3258Count Substrings That Satisfy K-Constraint I
3261Count Substrings That Satisfy K-Constraint II
3264Final Array State After K Multiplication Operations I
3266Final Array State After K Multiplication Operations II
3291Minimum Number of Valid Strings to Form Target I
3292Minimum Number of Valid Strings to Form Target II
3297Count Substrings That Can Be Rearranged to Contain a String I
3298Count Substrings That Can Be Rearranged to Contain a String II
3305Count of Substrings Containing Every Vowel and K Consonants I
3306Count of Substrings Containing Every Vowel and K Consonants II
3318Find X-Sum of All K-Long Subarrays I
3321Find X-Sum of All K-Long Subarrays II
3323Minimize Connected Groups by Inserting Interval
3325Count Substrings With K-Frequency Characters I
3329Count Substrings With K-Frequency Characters II
3346Maximum Frequency of an Element After Performing Operations I
3347Maximum Frequency of an Element After Performing Operations II
3364Minimum Positive Sum Subarray
3413Maximum Coins From K Consecutive Bags
3420Count Non-Decreasing Subarrays After K Operations
3422Minimum Operations to Make Subarray Elements Equal
3425Longest Special Path
3428Maximum and Minimum Sums of at Most Size K Subsequences
3430Maximum and Minimum Sums of at Most Size K Subarrays
3439Reschedule Meetings for Maximum Free Time I
3445Maximum Difference Between Even and Odd Frequency II
3455Shortest Matching Substring
3460Longest Common Prefix After at Most One Removal
3464Maximize the Distance Between Points on a Square
3474Lexicographically Smallest Generated String
3478Choose K Elements With Maximum Sum
3486Longest Special Path II
3555Smallest Subarray to Sort in Every Sliding Window
3567Minimum Absolute Difference in Sliding Submatrix
3578Count Partitions With Max-Min Difference at Most K
3584Maximum Product of First and Last Elements of a Subsequence
3589Count Prime-Gap Balanced Subarrays
3634Minimum Removals to Balance Array
3640Trionic Array II
3641Longest Semi-Repeating Subarray
3649Number of Perfect Pairs
3652Best Time to Buy and Sell Stock using Strategy
3656Determine if a Simple Graph Exists
3661Maximum Walls Destroyed by Robots
3672Sum of Weighted Modes in Subarrays
3679Minimum Discards to Balance Inventory
3691Maximum Total Subarray Value II
3698Split Array With Minimum Difference
3740Minimum Distance Between Three Equal Elements I
3741Minimum Distance Between Three Equal Elements II
3752Lexicographically Smallest Negated Permutation that Sums to Target
3766Minimum Operations to Make Binary Palindrome
3768Minimum Inversion Count in Subarrays of Fixed Length
3795Minimum Subarray Length With Distinct Sum At Least K
3797Count Routes to Climb a Rectangular Grid
3802Number of Ways to Paint Sheets
3835Count Subarrays With Cost Less Than or Equal to K
3844Longest Almost-Palindromic Substring
3845Maximum Subarray XOR with Bounded Range
3851Maximum Requests Without Violating the Limit
3853Merge Close Characters
3859Count Subarrays With K Distinct Integers
3867Sum of GCD of Formed Pairs
3872Longest Arithmetic Sequence After Changing At Most One Element
3874Valid Subarrays With Exactly One Peak
3937Minimum Operations to Make Array Modulo Alternating I
3944Minimum Operations to Make Array Modulo Alternating II
3969Valid Subarrays With Matching Sum Digits I
3972Valid Subarrays With Matching Sum Digits II