[go: up one dir, main page]

0% found this document useful (0 votes)
5 views5 pages

Two Pointers Practice Concept

The document outlines various techniques for solving problems using two-pointer strategies, including running from both ends of an array, slow and fast pointers, merging two arrays, and split & merge approaches. It lists numerous problems and their corresponding categories, such as the 2 Sum Problem, Trapping Water, and Linked List Operations. Each category includes specific problems that can be addressed using the two-pointer method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Two Pointers Practice Concept

The document outlines various techniques for solving problems using two-pointer strategies, including running from both ends of an array, slow and fast pointers, merging two arrays, and split & merge approaches. It lists numerous problems and their corresponding categories, such as the 2 Sum Problem, Trapping Water, and Linked List Operations. Each category includes specific problems that can be addressed using the two-pointer method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TWO POINTERS

-Kanik Chawla
1. Running from Both Ends of an Array
This category involves having two pointers at the left and right ends of an array, then
moving them toward the center while processing something with them.

●​ 2 Sum Problem​

○​ Two Sum II: Input Array is Sorted


○​ 3Sum
○​ 4Sum
○​ Number of Subsequences That Satisfy the Given Sum Condition
○​ Two Sum IV: Input is a BST
○​ Sum of Square Numbers
○​ Boats to Save People
○​ Minimize Maximum Pair Sum in Array
○​ 3Sum with Multiplicity
●​ Trapping Water​

○​ Trapping Rain Water


○​ Container With Most Water
●​ Next Permutation​

○​ Next Permutation
○​ Next Greater Element III
○​ Minimum Adjacent Swaps to Reach the Kth Smallest Number
●​ Reversing / Swapping​

○​ Valid Palindrome
○​ Reverse String
○​ Reverse Vowels of a String
○​ Valid Palindrome II
○​ Reverse Only Letters
○​ Remove Element
○​ Sort Colors
○​ Flipping an Image
○​ Squares of a Sorted Array
○​ Sort Array by Parity
○​ Sort Array by Parity II
○​ Pancake Sorting
○​ Reverse Prefix of Word
○​ Reverse String II
○​ Reverse Words in a String
○​ Reverse Words in a String III
●​ Others​

○​ Bag of Tokens
○​ DI String Match
○​ Minimum Length of String After Deleting Similar Ends
○​ Sentence Similarity III
○​ Find K Closest Elements
○​ Shortest Distance to a Character

2. Slow & Fast Pointers


This type involves using two pointers that move at different speeds. Typically, one
pointer advances faster, giving feedback to the slower pointer, and you use that
feedback for some calculation.

●​ Linked List Operations​

○​ Linked List Cycle


○​ Linked List Cycle II
○​ Remove Nth Node from End of List
○​ Rotate List
○​ Reorder List
○​ Palindrome Linked List
●​ Cyclic Detection​

○​ Find the Duplicate Number


○​ Circular Array Loop
●​ Sliding Window / Caterpillar Method​

○​ Number of Subarrays with Bounded Maximum


○​ Find Kth Smallest Pair Distance
○​ Moving Stones Until Consecutive II
○​ Count Pairs of Nodes
○​ Count Binary Substrings
○​ K-diff Pairs in an Array
●​ Rotation​

○​ Rotating the Box


○​ Rotate Array
●​ String​

○​ String Compression
○​ Last Substring in Lexicographical Order
●​ Remove Duplicate​

○​ Remove Duplicates from Sorted Array


○​ Remove Duplicates from Sorted Array II
○​ Remove Duplicates from Sorted List II
○​ Duplicate Zeros
●​ Others​

○​ Statistics from a Large Sample


○​ Partition Labels
○​ Magical String
○​ Friends of Appropriate Ages
○​ Longest Mountain in Array
○​ Shortest Subarray to be Removed to Make Array Sorted

3. Running from Beginning of 2 Arrays / Merging 2 Arrays


In this category, you will be given two arrays or lists, and you need to process them
with individual pointers.
●​ Sorted Arrays​

○​ Merge Sorted Array


○​ Heaters
○​ Find the Distance Value Between Two Arrays
●​ Intersections / LCA Like​

○​ Intersection of Two Linked Lists


○​ Intersection of Two Arrays
○​ Intersection of Two Arrays II
●​ Substring​

○​ Implement StrStr
○​ Longest Word in Dictionary Through Deleting
○​ Long Pressed Name
○​ Longest Uncommon Subsequence II
○​ Compare Version Numbers
○​ Camelcase Matching
○​ Expressive Words
●​ Median Finder​

○​ Find Median from Data Stream


●​ Meet-in-the-middle / Binary Search​

○​ Partition Array into Two Arrays to Minimize Sum Difference


○​ Closest Subsequence Sum
○​ Ways to Split Array into Three Subarrays
○​ 3Sum Closest
○​ Valid Triangle Number
●​ Others​
○​ Shortest Unsorted Continuous Subarray
○​ Most Profit Assigning Work
○​ Largest Merge of Two Strings
○​ Swap Adjacent in LR String

4. Split & Merge of an Array / Divide & Conquer


This category is similar to the previous one but involves first splitting the list into two
separate lists and then using the two-pointer approach to merge or unify them. There
aren't too many tasks in this category.

●​ Partition​

○​ Partition List
●​ Sorting​

○​ Sort List

You might also like