# Two pointers approach #### 2022-06-14 23:06 --- ##### Algorithms: #algorithm #two_pointers ##### Data structures: #array #linked_list ##### Difficulty: #CS_analysis ##### Related problems: ##### Links: - [leetcode](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/) - [Two-pointers and sliding windows](https://leetcode.com/problems/subarray-sum-equals-k/discuss/301242/General-summary-of-what-kind-of-problem-can-cannot-solved-by-Two-Pointers) --- ### What is Two pointers approach? By using two pointers, to in place modify array elements. - One fast and one slow [[Leetcode Best-Time-To-Buy-And-Sell-Stock]] or [[Leetcode Linked-List-Cycle]] - The two are unordered [[Leetcode Merge-Two-Sorted-Lists]] ### Why and when to use it? - There are two arrays, or linked lists - They are sorted, or operation in place will not interfere elements after. ### When not use it? Refer to [this link](https://leetcode.com/problems/subarray-sum-equals-k/discuss/301242/General-summary-of-what-kind-of-problem-can-cannot-solved-by-Two-Pointers) #TODO: complete this section