Leetcode code templates
Two pointers: one input, opposite ends def fn(arr): left = ans = 0 right = len(arr) - 1 while left < right: # do some logic here with left and right if CONDITION: left += 1 else: right -= 1 return ans Two pointers: two inputs, exhaust both def fn(arr1, arr2): i = j = ans = 0 while i < len(arr1...
May 18, 2026