Practice · 15 problems
Two Pointers
0 of 15 solved on this device
- 007Valid PalindromeGiven a string `s`, return `true` if it is a palindrome after converting all uppercase letters to lowercase and removing every non-alphanumeric character.Easy
- 0083SumGiven an integer array `nums`, return all unique triplets `[nums[i], nums[j], nums[k]]` with distinct indices such that they sum to zero. The solution set must not contain duplicate triplets.Medium
- 009Container With Most WaterGiven an integer array `height` where each value is a vertical line at that index, find two lines that together with the x-axis form a container holding the most water. Return the maximum area. You may not slant the container.Medium
- 010Trapping Rain WaterGiven `n` non-negative integers representing an elevation map where the width of each bar is 1, compute how much rain water can be trapped after raining.Hard
- 054Remove Duplicates from Sorted ArrayGiven a sorted array `nums`, remove the duplicates IN PLACE so each unique element appears once, keeping the relative order. Return `k`, the number of unique elements; the first k slots of nums must hold them. What is left beyond k does not matter.Easy
- 055Two Sum II - Input Array Is SortedGiven a 1-indexed array `numbers` sorted in non-decreasing order, find two numbers that add up to `target` and return their 1-based indices [index1, index2] with index1 < index2. You must use O(1) extra space.Medium
- 056Sort ColorsGiven an array `nums` with n objects colored 0 (red), 1 (white) or 2 (blue), sort them IN PLACE so equal colors are adjacent in the order 0, 1, 2. You may not use a library sort, and should do it in one pass.Medium
- 171Valid Palindrome IIGiven a string `s`, return true if `s` can be a palindrome after deleting AT MOST one character from it.Easy
- 172Squares of a Sorted ArrayGiven an integer array `nums` sorted in non-decreasing order, return an array of the squares of each number, also sorted in non-decreasing order.Easy
- 173Is SubsequenceGiven two strings `s` and `t`, return true if `s` is a subsequence of `t`: it can be formed by deleting some (possibly zero) characters of `t` without changing the order of the rest.Easy
- 174Reverse StringWrite a function that reverses an array of characters `s` IN PLACE. Do not return anything; modify `s` directly using O(1) extra memory.Easy
- 1753Sum ClosestGiven an integer array `nums` of length n and an integer `target`, find three integers at distinct indices whose sum is closest to `target`. Return that SUM.Medium
- 1764SumGiven an array `nums` of n integers, return all UNIQUE quadruplets [nums[a], nums[b], nums[c], nums[d]] with distinct indices a, b, c, d whose sum equals `target`. The quadruplets and the numbers inside them may be in any order.Medium
- 177Boats to Save People`people[i]` is the weight of person i, and every boat can carry at most `limit` weight. Each boat carries AT MOST TWO people at once, provided their total weight is <= limit. Return the minimum number of boats needed to carry everyone.Medium
- 178Next PermutationRearrange `nums` IN PLACE into the next lexicographically greater permutation. If no greater permutation exists (the array is in descending order), rearrange it into the lowest possible order (ascending). Use only O(1) extra memory and return nothing.Medium