Two Pointers Interview Questions

Opposite or same-direction pointers on arrays and strings.

193 problems

#Title
153 Sum
163 Sum Closest
184 Sum
19Remove Nth Node From End of List
86Partition List
141Linked List Cycle
142Linked List Cycle II
143Reorder List
167Two Sum II - Input array is sorted
209Minimum Size Subarray Sum
2593Sum Smaller
283Move Zeroes
287Find the Duplicate Number
344Reverse String
345Reverse Vowels of a String
349Intersection of Two Arrays
350Intersection of Two Arrays II
360Sort Transformed Array
424Longest Repeating Character Replacement
457Circular Array Loop
567Permutation in String
611Valid Triangle Number
777Swap Adjacent in LR String
826Most Profit Assigning Work
828Count Unique Characters of All Substrings of a Given String
844Backspace String Compare
862Shortest Subarray with Sum at Least K
876Middle of the Linked List
904Fruit Into Baskets
930Binary Subarrays With Sum
977Squares of a Sorted Array
992Subarrays with K Different Integers
1004Max Consecutive Ones III
1033Moving Stones Until Consecutive
1040Moving Stones Until Consecutive II
1151Minimum Swaps to Group All 1's Together
1156Swap For Longest Repeated Character Substring
1169Invalid Transactions
1176Diet Plan Performance
1208Get Equal Substrings Within Budget
1213Intersection of Three Sorted Arrays
1214Two Sum BSTs
1234Replace the Substring for Balanced String
1248Count Number of Nice Subarrays
1297Maximum Number of Occurrences of a Substring
1305All Elements in Two Binary Search Trees
1316Distinct Echo Substrings
1358Number of Substrings Containing All Three Characters
1423Maximum Points You Can Obtain from Cards
1425Constrained Subset Sum
1456Maximum Number of Vowels in a Substring of Given Length
1493Longest Subarray of 1's After Deleting One Element
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
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
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
2024Maximize the Confusion of an Exam
2040Kth Smallest Product of Two Sorted Arrays
2046Sort Linked List Already Sorted Using Absolute Values
2062Count Vowel Substrings of a String
2067Number of Equal Count Substrings
2090K Radius Subarray Averages
2105Watering Plants II
2107Number of Unique Flavors After Sharing K Candies
2134Minimum Swaps to Group All 1's Together II
2149Rearrange Array Elements by Sign
2161Partition Array According to Given Pivot
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
2379Minimum Recolors to Get K Consecutive Black Blocks
2393Count Strictly Increasing Subarrays
2401Longest Nice Subarray
2444Count Subarrays With Fixed Bounds
2461Maximum Sum of Distinct Subarrays With Length K
2465Number of Distinct Averages
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
2570Merge Two 2D Arrays by Summing Values
2609Find the Longest Balanced Substring of a Binary String
2653Sliding Subarray Beauty
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
2831Find the Longest Equal Subarray
2838Maximum Coins Heroes Can Collect
2841Maximum Sum of Almost Unique Subarray
2875Minimum Size Subarray in Infinite Array
2904Shortest and Lexicographically Smallest Beautiful String
2933High-Access Employees
2938Separate Black and White Balls
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
3013Divide an Array Into Subarrays With Minimum Cost II
3085Minimum Deletions to Make String K-Special
3090Maximum Length Substring With Two Occurrences
3095Shortest Subarray With OR at Least K I
3097Shortest Subarray With OR at Least K II
3171Find Subarray With Bitwise OR Closest to K
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
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
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
3460Longest Common Prefix After at Most One Removal
3485Longest Common Prefix of K Strings After Removal
3486Longest Special Path II
3555Smallest Subarray to Sort in Every Sliding Window
3567Minimum Absolute Difference in Sliding Submatrix
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
3672Sum of Weighted Modes in Subarrays
3679Minimum Discards to Balance Inventory
3698Split Array With Minimum Difference
3740Minimum Distance Between Three Equal Elements I
3741Minimum Distance Between Three Equal Elements II
3768Minimum Inversion Count in Subarrays of Fixed Length
3795Minimum Subarray Length With Distinct Sum At Least K
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
3859Count Subarrays With K Distinct Integers
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