Reverse Vowels of a String
Reverse only the vowels of a string in place using two pointers, in O(n) time.
958 published notes across every category.
Reverse only the vowels of a string in place using two pointers, in O(n) time.
Remove all occurrences of a value from an array in place using the slow/fast two pointer pattern, returning the new length in O(n).
Move all zeroes to the end of an array while keeping the order of non-zero elements, using two pointers in O(n) time and O(1) space.
Find the sum of three integers closest to a target using sorting plus the two pointer technique, in O(n^2) time.
Find all unique quadruplets that sum to a target using sorting, nested loops, and two pointers, in O(n^3) time.
Rearrange an array so even numbers come before odd numbers using two pointers, in place in O(n) time.
Return the squares of a sorted array in sorted order using two pointers from both ends, in O(n) time.
Merge two sorted arrays in place using two pointers from the back, in O(m+n) time and O(1) space.
Find the intersection of two arrays including duplicates using sorting and two pointers, in O(n log n) time.
Compare two strings containing backspace characters using two pointers scanning from the end, in O(n) time and O(1) space.
Compute how much rain water is trapped between bars using the two pointer technique with running max heights, in O(n) time and O(1) space.
Find two lines that hold the most water using two pointers from both ends, moving the shorter line inward, in O(n) time.