Two Pointers Problems
Master two pointers problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 159 problems in this category.
Total Problems: 159
Easy: 51
Medium: 92
Hard: 16
Showing 50 of 159 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Two Pointers LeetCode Problems List
- 5. Longest Palindromic Substring - Medium - Two PointersGiven a string s, return the longest palindromic substring in s.... Topics: Two Pointers, String, Dynamic Programming
- 202. Happy Number - Easy - Two PointersWrite an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive intege... Topics: Hash Table, Math, Two Pointers
- 15. 3Sum - Medium - Two PointersGiven an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k]... Topics: Array, Two Pointers, Sorting
- 88. Merge Sorted Array - Easy - Two PointersYou are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in num... Topics: Array, Two Pointers, Sorting
- 18. 4Sum - Medium - Two PointersGiven an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n a... Topics: Array, Two Pointers, Sorting
- 344. Reverse String - Easy - Two PointersWrite a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place... Topics: Two Pointers, String
- 11. Container With Most Water - Medium - Two PointersYou are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, hei... Topics: Array, Two Pointers, Greedy
- 75. Sort Colors - Medium - Two PointersGiven an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in ... Topics: Array, Two Pointers, Sorting
- 141. Linked List Cycle - Easy - Two PointersGiven head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the ... Topics: Hash Table, Linked List, Two Pointers
- 42. Trapping Rain Water - Hard - Two PointersGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.... Topics: Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack
- 151. Reverse Words in a String - Medium - Two PointersGiven an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by ... Topics: Two Pointers, String
- 125. Valid Palindrome - Easy - Two PointersA phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the ... Topics: Two Pointers, String
- 26. Remove Duplicates from Sorted Array - Easy - Two PointersGiven an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relati... Topics: Array, Two Pointers
- 19. Remove Nth Node From End of List - Medium - Two PointersGiven the head of a linked list, remove the nth node from the end of the list and return its head.... Topics: Linked List, Two Pointers
- 295. Find Median from Data Stream - Hard - Two PointersThe median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of th... Topics: Two Pointers, Design, Sorting, Heap (Priority Queue), Data Stream
- 167. Two Sum II - Input Array Is Sorted - Medium - Two PointersGiven a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific targe... Topics: Array, Two Pointers, Binary Search
- 234. Palindrome Linked List - Easy - Two PointersGiven the head of a singly linked list, return true if it is a palindrome or false otherwise.... Topics: Linked List, Two Pointers, Stack, Recursion
- 567. Permutation in String - Medium - Two PointersGiven two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permutatio... Topics: Hash Table, Two Pointers, String, Sliding Window
- 31. Next Permutation - Medium - Two PointersA permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following ... Topics: Array, Two Pointers
- 189. Rotate Array - Medium - Two PointersGiven an integer array nums, rotate the array to the right by k steps, where k is non-negative.... Topics: Array, Math, Two Pointers
- 653. Two Sum IV - Input is a BST - Easy - Two PointersGiven the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or fals... Topics: Hash Table, Two Pointers, Tree, Depth-First Search, Breadth-First Search, Binary Search Tree, Binary Tree
- 160. Intersection of Two Linked Lists - Easy - Two PointersGiven the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersec... Topics: Hash Table, Linked List, Two Pointers
- 148. Sort List - Medium - Two PointersGiven the head of a linked list, return the list after sorting it in ascending order.... Topics: Linked List, Two Pointers, Divide and Conquer, Sorting, Merge Sort
- 1019. Squares of a Sorted Array - Easy - Two PointersGiven an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.... Topics: Array, Two Pointers, Sorting
- 287. Find the Duplicate Number - Medium - Two PointersGiven an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nu... Topics: Array, Two Pointers, Binary Search, Bit Manipulation
- 16. 3Sum Closest - Medium - Two PointersGiven an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of t... Topics: Array, Two Pointers, Sorting
- 908. Middle of the Linked List - Easy - Two PointersGiven the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.... Topics: Linked List, Two Pointers
- 27. Remove Element - Easy - Two PointersGiven an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return ... Topics: Array, Two Pointers
- 658. Find K Closest Elements - Medium - Two PointersGiven a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending... Topics: Array, Two Pointers, Binary Search, Sliding Window, Sorting, Heap (Priority Queue)
- 443. String Compression - Medium - Two PointersGiven an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating c... Topics: Two Pointers, String
- 349. Intersection of Two Arrays - Easy - Two PointersGiven two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the resu... Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
- 647. Palindromic Substrings - Medium - Two PointersGiven a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring ... Topics: Two Pointers, String, Dynamic Programming
- 143. Reorder List - Medium - Two PointersYou are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form... Topics: Linked List, Two Pointers, Stack, Recursion
- 680. Valid Palindrome II - Easy - Two PointersGiven a string s, return true if the s can be palindrome after deleting at most one character from it.... Topics: Two Pointers, String, Greedy
- 350. Intersection of Two Arrays II - Easy - Two PointersGiven two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in b... Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
- 28. Find the Index of the First Occurrence in a String - Easy - Two PointersGiven two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.... Topics: Two Pointers, String, String Matching
- 283. Move Zeroes - Easy - Two PointersGiven an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this i... Topics: Array, Two Pointers
- 61. Rotate List - Medium - Two PointersGiven the head of a linked list, rotate the list to the right by k places.... Topics: Linked List, Two Pointers
- 557. Reverse Words in a String III - Easy - Two PointersGiven a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.... Topics: Two Pointers, String
- 142. Linked List Cycle II - Medium - Two PointersGiven the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there... Topics: Hash Table, Linked List, Two Pointers
- 80. Remove Duplicates from Sorted Array II - Medium - Two PointersGiven an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The r... Topics: Array, Two Pointers
- 82. Remove Duplicates from Sorted List II - Medium - Two PointersGiven the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the... Topics: Linked List, Two Pointers
- 861. Flipping an Image - Easy - Two PointersGiven an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means t... Topics: Array, Two Pointers, Bit Manipulation, Matrix, Simulation
- 86. Partition List - Medium - Two PointersGiven the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should p... Topics: Linked List, Two Pointers
- 1028. Interval List Intersections - Medium - Two PointersYou are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each li... Topics: Array, Two Pointers, Line Sweep
- 528. Swapping Nodes in a Linked List - Medium - Two PointersYou are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the kth node from the begin... Topics: Linked List, Two Pointers
- 457. Circular Array Loop - Medium - Two PointersYou are playing a game involving a circular array of non-zero integers nums. Each nums[i] denotes the number of indices forward/backward you must move... Topics: Array, Hash Table, Two Pointers
- 165. Compare Version Numbers - Medium - Two PointersGiven two version strings, version1 and version2, compare them. A version string consists of revisions separated by dots '.'. The value of the revisio... Topics: Two Pointers, String
- 541. Reverse String II - Easy - Two PointersGiven a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer th... Topics: Two Pointers, String
- 1009. Pancake Sorting - Medium - Two PointersGiven an array of integers arr, sort the array by performing a series of pancake flips. In one pancake flip we do the following steps: Choose an integ... Topics: Array, Two Pointers, Greedy, Sorting
- 768. Partition Labels - Medium - Two PointersYou are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example,... Topics: Hash Table, Two Pointers, String, Greedy
- 392. Is Subsequence - Easy - Two PointersGiven two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from t... Topics: Two Pointers, String, Dynamic Programming
- 874. Backspace String Compare - Easy - Two PointersGiven two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that after... Topics: Two Pointers, String, Stack, Simulation
- 1798. Max Number of K-Sum Pairs - Medium - Two PointersYou are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them fro... Topics: Array, Hash Table, Two Pointers, Sorting
- 581. Shortest Unsorted Continuous Subarray - Medium - Two PointersGiven an integer array nums, you need to find one continuous subarray such that if you only sort this subarray in non-decreasing order, then the whole... Topics: Array, Two Pointers, Stack, Greedy, Sorting, Monotonic Stack
- 321. Create Maximum Number - Hard - Two PointersYou are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also gi... Topics: Array, Two Pointers, Stack, Greedy, Monotonic Stack
- 1129. Longest String Chain - Medium - Two PointersYou are given an array of words where each word consists of lowercase English letters. wordA is a predecessor of wordB if and only if we can insert ex... Topics: Array, Hash Table, Two Pointers, String, Dynamic Programming, Sorting
- 953. Reverse Only Letters - Easy - Two PointersGiven a string s, reverse the string according to the following rules: All the characters that are not English letters remain in the same position. Al... Topics: Two Pointers, String
- 2216. Delete the Middle Node of a Linked List - Medium - Two PointersYou are given the head of a linked list. Delete the middle node, and return the head of the modified linked list. The middle node of a linked list of ... Topics: Linked List, Two Pointers
- 2488. Divide Intervals Into Minimum Number of Groups - Medium - Two PointersYou are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti]. You have to divide ... Topics: Array, Two Pointers, Greedy, Sorting, Heap (Priority Queue), Prefix Sum
- 3437. Maximum Total Damage With Spell Casting - Medium - Two PointersA magician has various spells. You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same da... Topics: Array, Hash Table, Two Pointers, Binary Search, Dynamic Programming, Sorting, Counting
- 2162. Partition Array Into Two Arrays to Minimize Sum Difference - Hard - Two PointersYou are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of t... Topics: Array, Two Pointers, Binary Search, Dynamic Programming, Bit Manipulation, Ordered Set, Bitmask
- 696. Count Binary Substrings - Easy - Two PointersGiven a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these ... Topics: Two Pointers, String
- 2602. Maximum Enemy Forts That Can Be Captured - Easy - Two PointersYou are given a 0-indexed integer array forts of length n representing the positions of several forts. forts[i] can be -1, 0, or 1 where: -1 represent... Topics: Array, Two Pointers
- 556. Next Greater Element III - Medium - Two PointersGiven a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If n... Topics: Math, Two Pointers, String
- 2392. Successful Pairs of Spells and Potions - Medium - Two PointersYou are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell... Topics: Array, Two Pointers, Binary Search, Sorting
- 611. Valid Triangle Number - Medium - Two PointersGiven an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
- 917. Boats to Save People - Medium - Two PointersYou are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum wei... Topics: Array, Two Pointers, Greedy, Sorting
- 1972. Rotating the Box - Medium - Two PointersYou are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following: A stone '#' A sta... Topics: Array, Two Pointers, Matrix
- 2271. Rearrange Array Elements by Sign - Medium - Two PointersYou are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers. You should return the arr... Topics: Array, Two Pointers, Simulation
- 811. Number of Subarrays with Bounded Maximum - Medium - Two PointersGiven an integer array nums and two integers left and right, return the number of contiguous non-empty subarrays such that the value of the maximum ar... Topics: Array, Two Pointers
- 2559. Maximum Number of Non-overlapping Palindrome Substrings - Hard - Two PointersYou are given a string s and a positive integer k. Select a set of non-overlapping substrings from the string s that satisfy the following conditions:... Topics: Two Pointers, String, Dynamic Programming, Greedy
- 481. Magical String - Medium - Two PointersA magical string s consists of only '1' and '2' and obeys the following rules: The string s is magical because concatenating the number of contiguous ... Topics: Two Pointers, String
- 941. Sort Array By Parity - Easy - Two PointersGiven an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfie... Topics: Array, Two Pointers, Sorting
- 1358. Find Positive Integer Solution for a Given Equation - Medium - Two PointersGiven a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y wher... Topics: Math, Two Pointers, Binary Search, Interactive
- 532. K-diff Pairs in an Array - Medium - Two PointersGiven an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nu... Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
- 1984. Maximum Distance Between a Pair of Values - Medium - Two PointersYou are given two non-increasing 0-indexed integer arrays nums1 and nums2. A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= ... Topics: Array, Two Pointers, Binary Search
- 875. Longest Mountain in Array - Medium - Two PointersYou may recall that an array arr is a mountain array if and only if: arr.length >= 3 There exists some index i (0-indexed) with 0 < i < arr.length - 1... Topics: Array, Two Pointers, Dynamic Programming, Enumeration
- 524. Longest Word in Dictionary through Deleting - Medium - Two PointersGiven a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string ch... Topics: Array, Two Pointers, String, Sorting
- 633. Sum of Square Numbers - Medium - Two PointersGiven a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.... Topics: Math, Two Pointers, Binary Search
- 1880. Largest Merge Of Two Strings - Medium - Two PointersYou are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choos... Topics: Two Pointers, String, Greedy
- 1356. Minimum Number of Moves to Make Palindrome - Hard - Two PointersYou are given a string s consisting only of lowercase English letters. In one move, you can select any two adjacent characters of s and swap them. Ret... Topics: Two Pointers, String, Greedy, Binary Indexed Tree
- 2128. Reverse Prefix of Word - Easy - Two PointersGiven a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ... Topics: Two Pointers, String, Stack
- 2664. Maximize Greatness of an Array - Medium - Two PointersYou are given a 0-indexed integer array nums. You are allowed to permute nums into a new array perm of your choosing. We define the greatness of nums ... Topics: Array, Two Pointers, Greedy, Sorting
- 2180. Maximum Number of Tasks You Can Assign - Hard - Two PointersYou have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] s... Topics: Array, Two Pointers, Binary Search, Greedy, Queue, Sorting, Monotonic Queue
- 2707. Merge Two 2D Arrays by Summing Values - Easy - Two PointersYou are given two 2D integer arrays nums1 and nums2. nums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali. nums2[... Topics: Array, Hash Table, Two Pointers
- 455. Assign Cookies - Easy - Two PointersAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g... Topics: Array, Two Pointers, Greedy, Sorting
- 2481. Strictly Palindromic Number - Medium - Two PointersAn integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is pal... Topics: Math, Two Pointers, Brainteaser
- 3959. Maximum Total from Optimal Activation Order - Medium - Two PointersYou are given two integer arrays value and limit, both of length n. Initially, all elements are inactive. You may activate them in any order. To activ... Topics: Array, Two Pointers, Greedy, Sorting, Heap (Priority Queue)
- 2588. Maximum Number of Points From Grid Queries - Hard - Two PointersYou are given an m x n integer matrix grid and an array queries of size k. Find an array answer of size k such that for each integer queries[i] you st... Topics: Array, Two Pointers, Breadth-First Search, Union Find, Sorting, Heap (Priority Queue), Matrix
- 2572. Append Characters to String to Make Subsequence - Medium - Two PointersYou are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to th... Topics: Two Pointers, String, Greedy
- 3967. Earliest Finish Time for Land and Water Rides II - Medium - Two PointersYou are given two categories of theme park attractions: land rides and water rides. Land rides landStartTime[i] – the earliest time the ith land ride ... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
- 2231. Find First Palindromic String in the Array - Easy - Two PointersGiven an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "". A string is ... Topics: Array, Two Pointers, String
- 2027. Maximum Number of Removable Characters - Medium - Two PointersYou are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset o... Topics: Array, Two Pointers, String, Binary Search
- 2551. Apply Operations to an Array - Easy - Two PointersYou are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith... Topics: Array, Two Pointers, Simulation
- 1080. Camelcase Matching - Medium - Two PointersGiven an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false... Topics: Array, Two Pointers, String, Trie, String Matching
- 3973. Flip Square Submatrix Vertically - Easy - Two PointersYou are given an m x n integer matrix grid, and three integers x, y, and k. The integers x and y represent the row and column indices of the top-left ... Topics: Array, Two Pointers, Matrix
- 3399. Find the Integer Added to Array II - Medium - Two PointersYou are given two integer arrays nums1 and nums2. From nums1 two elements have been removed, and all other elements have been increased (or decreased ... Topics: Array, Two Pointers, Sorting, Enumeration
- 2265. Partition Array According to Given Pivot - Medium - Two PointersYou are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied: Every element less... Topics: Array, Two Pointers, Simulation
- 2497. Maximum Matching of Players With Trainers - Medium - Two PointersYou are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer arr... Topics: Array, Two Pointers, Greedy, Sorting
- 853. Most Profit Assigning Work - Medium - Two PointersYou have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where: difficulty[i] and profit[i] are the difficulty and th... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
- 1923. Sentence Similarity III - Medium - Two PointersYou are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by... Topics: Array, Two Pointers, String
- 3195. Separate Black and White Balls - Medium - Two PointersThere are n balls on a table, each ball has a color black or white. You are given a 0-indexed binary string s of length n, where 1 and 0 represent bla... Topics: Two Pointers, String, Greedy
- 2816. Lexicographically Smallest Palindrome - Easy - Two PointersYou are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a... Topics: Two Pointers, String, Greedy
- 3303. Find Beautiful Indices in the Given Array II - Hard - Two PointersYou are given a 0-indexed string s, a string a, a string b, and an integer k. An index i is beautiful if: 0 <= i <= s.length - a.length s[i..(i + a.le... Topics: Two Pointers, String, Binary Search, Rolling Hash, String Matching, Hash Function
- 2232. Adding Spaces to a String - Medium - Two PointersYou are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. ... Topics: Array, Two Pointers, String, Simulation
- 979. DI String Match - Easy - Two PointersA permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where: s[i] == 'I' if perm[i... Topics: Array, Two Pointers, String, Greedy
- 3965. Earliest Finish Time for Land and Water Rides I - Easy - Two PointersYou are given two categories of theme park attractions: land rides and water rides. Land rides landStartTime[i] – the earliest time the ith land ride ... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
- 1566. Check If a Word Occurs As a Prefix of Any Word in a Sentence - Easy - Two PointersGiven a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence. R... Topics: Two Pointers, String, String Matching
- 1894. Merge Strings Alternately - Easy - Two PointersYou are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than t... Topics: Two Pointers, String
- 958. Sort Array By Parity II - Easy - Two PointersGiven an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i ... Topics: Array, Two Pointers, Sorting
- 2442. Number of Arithmetic Triplets - Easy - Two PointersYou are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the fol... Topics: Array, Hash Table, Two Pointers, Enumeration
- 1918. Maximum Score of a Good Subarray - Hard - Two PointersYou are given an array of integers nums (0-indexed) and an integer k. The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j... Topics: Array, Two Pointers, Binary Search, Stack, Monotonic Stack
- 802. K-th Smallest Prime Fraction - Medium - Two PointersYou are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k. Fo... Topics: Array, Two Pointers, Binary Search, Sorting, Heap (Priority Queue)
- 2699. Count the Number of Fair Pairs - Medium - Two PointersGiven a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs. A pair (i, j) is fair if: 0 <= i < j... Topics: Array, Two Pointers, Binary Search, Sorting
- 1699. Number of Ways Where Square of Number Is Equal to Product of Two Numbers - Medium - Two PointersGiven two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: Type 1: Triplet (i, ... Topics: Array, Hash Table, Math, Two Pointers
- 2417. The Latest Time to Catch a Bus - Medium - Two PointersYou are given a 0-indexed integer array buses of length n, where buses[i] represents the departure time of the ith bus. You are also given a 0-indexed... Topics: Array, Two Pointers, Binary Search, Sorting
- 901. Advantage Shuffle - Medium - Two PointersYou are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for ... Topics: Array, Two Pointers, Greedy, Sorting
- 2701. Subsequence With the Minimum Score - Hard - Two PointersYou are given two strings s and t. You are allowed to remove any number of characters from the string t. The score of the string is 0 if no characters... Topics: Two Pointers, String, Binary Search
- 3683. Find the Lexicographically Largest String From the Box I - Medium - Two PointersYou are given a string word, and an integer numFriends. Alice is organizing a game for her numFriends friends. There are multiple rounds in the game, ... Topics: Two Pointers, String, Enumeration
- 3755. Maximum Product of First and Last Elements of a Subsequence - Medium - Two PointersYou are given an integer array nums and an integer m. Return the maximum product of the first and last elements of any subsequence of nums of size m.... Topics: Array, Two Pointers
- 2561. Number of Distinct Averages - Easy - Two PointersYou are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and ... Topics: Array, Hash Table, Two Pointers, Sorting
- 3165. Find Indices With Index and Value Difference I - Easy - Two PointersYou are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference. Your task is to find two ind... Topics: Array, Two Pointers
- 1988. Minimize Maximum Pair Sum in Array - Medium - Two PointersThe pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), ... Topics: Array, Two Pointers, Greedy, Sorting
- 1831. Ways to Split Array Into Three Subarrays - Medium - Two PointersA split of an integer array is good if: The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left t... Topics: Array, Two Pointers, Binary Search, Prefix Sum
- 827. Expressive Words - Medium - Two PointersSometimes people repeat letters to represent extra feeling. For example: "hello" -> "heeellooo" "hi" -> "hiiii" In these strings like "heeellooo", we ... Topics: Array, Two Pointers, String
- 852. Friends Of Appropriate Ages - Medium - Two PointersThere are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person. A Person x will not sen... Topics: Array, Two Pointers, Binary Search, Sorting
- 2330. Maximum Total Beauty of the Gardens - Hard - Two PointersAlice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens. You are given a 0-indexed integer ar... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting, Enumeration, Prefix Sum
- 3170. Find Indices With Index and Value Difference II - Medium - Two PointersYou are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference. Your task is to find two ind... Topics: Array, Two Pointers
- 2095. Minimum Number of Swaps to Make the String Balanced - Medium - Two PointersYou are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. A strin... Topics: Two Pointers, String, Stack, Greedy
- 2320. Find All K-Distant Indices in an Array - Easy - Two PointersYou are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one i... Topics: Array, Two Pointers
- 3793. Longest Palindrome After Substring Concatenation I - Medium - Two PointersYou are given two strings, s and t. You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empt... Topics: Two Pointers, String, Dynamic Programming, Enumeration
- 1468. Check If N and Its Double Exist - Easy - Two PointersGiven an array arr of integers, check if there exist two indices i and j such that : i != j 0 <= i, j < arr.length arr[i] == 2 * arr[j]... Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
- 2553. Total Cost to Hire K Workers - Medium - Two PointersYou are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. W... Topics: Array, Two Pointers, Heap (Priority Queue), Simulation
- 1850. Minimum Length of String After Deleting Similar Ends - Medium - Two PointersGiven a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times: Pi... Topics: Two Pointers, String
- 345. Reverse Vowels of a String - Easy - Two PointersGiven a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both low... Topics: Two Pointers, String
- 1659. Get the Maximum Score - Hard - Two PointersYou are given two sorted arrays of distinct integers nums1 and nums2. A valid path is defined as follows: Choose array nums1 or nums2 to traverse (fro... Topics: Array, Two Pointers, Dynamic Programming, Greedy
- 1168. Duplicate Zeros - Easy - Two PointersGiven a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond the... Topics: Array, Two Pointers
- 2581. Divide Players Into Teams of Equal Skill - Medium - Two PointersYou are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams ... Topics: Array, Hash Table, Two Pointers, Sorting
- 2093. Check If String Is a Prefix of Array - Easy - Two PointersGiven a string s and an array of strings words, determine whether s is a prefix string of words. A string s is a prefix string of words if s can be ma... Topics: Array, Two Pointers, String
- 959. 3Sum With Multiplicity - Medium - Two PointersGiven an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target. As ... Topics: Array, Hash Table, Two Pointers, Sorting, Counting
- 1621. Number of Subsequences That Satisfy the Given Sum Condition - Medium - Two PointersYou are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum an... Topics: Array, Two Pointers, Binary Search, Sorting
- 475. Heaters - Medium - Two PointersWinter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. Every house can b... Topics: Array, Two Pointers, Binary Search, Sorting
- 868. Push Dominoes - Medium - Two PointersThere are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to t... Topics: Two Pointers, String, Dynamic Programming
- 1002. Maximum Width Ramp - Medium - Two PointersA ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i. Given an integer array num... Topics: Array, Two Pointers, Stack, Monotonic Stack
- 961. Long Pressed Name - Easy - Two PointersYour friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed ... Topics: Two Pointers, String
- 2917. Count Pairs Whose Sum is Less than Target - Easy - Two PointersGiven a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] <... Topics: Array, Two Pointers, Binary Search, Sorting
- 841. Shortest Distance to a Character - Easy - Two PointersGiven a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance ... Topics: Array, Two Pointers, String
- 2712. Find the Maximum Number of Marked Indices - Medium - Two PointersYou are given a 0-indexed integer array nums. Initially, all of the indices are unmarked. You are allowed to make this operation any number of times: ... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting
- 2634. Minimum Common Value - Easy - Two PointersGiven two integer arrays nums1 and nums2, sorted in non-decreasing order, return the minimum integer common to both arrays. If there is no common inte... Topics: Array, Hash Table, Two Pointers, Binary Search
- 2236. Maximum Twin Sum of a Linked List - Medium - Two PointersIn a linked list of size n, where n is even, the ith node (0-indexed) of the linked list is known as the twin of the (n-1-i)th node, if 0 <= i <= (n /... Topics: Linked List, Two Pointers, Stack
- 1133. Last Substring in Lexicographical Order - Hard - Two PointersGiven a string s, return the last substring of s in lexicographical order.... Topics: Two Pointers, String
- 2228. Watering Plants II - Medium - Two PointersAlice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the it... Topics: Array, Two Pointers, Simulation
- 2414. Move Pieces to Obtain a String - Medium - Two PointersYou are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' ... Topics: Two Pointers, String
- 1881. Closest Subsequence Sum - Hard - Two PointersYou are given an integer array nums and an integer goal. You want to choose a subsequence of nums such that the sum of its elements is the closest pos... Topics: Array, Two Pointers, Dynamic Programming, Bit Manipulation, Sorting, Bitmask
- 2524. Largest Positive Integer That Exists With Its Negative - Easy - Two PointersGiven an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array. Return the pos... Topics: Array, Hash Table, Two Pointers, Sorting
- 3487. Find Maximum Removals From Source String - Medium - Two PointersYou are given a string source of size n, a string pattern that is a subsequence of source, and a sorted integer array targetIndices that contains dist... Topics: Array, Hash Table, Two Pointers, String, Dynamic Programming
- 1581. The k Strongest Values in an Array - Medium - Two PointersGiven an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is t... Topics: Array, Two Pointers, Sorting
- 1815. Checking Existence of Edge Length Limited Paths - Hard - Two PointersAn undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. ... Topics: Array, Two Pointers, Union Find, Graph, Sorting
Related LeetCode Topics
- Array LeetCode Problems
- Backtracking LeetCode Problems
- Biconnected Component LeetCode Problems
- Binary Indexed Tree LeetCode Problems
- Binary Search LeetCode Problems
- Binary Search Tree LeetCode Problems
- Binary Tree LeetCode Problems
- Bit Manipulation LeetCode Problems
- Bitmask LeetCode Problems
- Brainteaser LeetCode Problems
- Breadth-First Search LeetCode Problems
- Bucket Sort LeetCode Problems
- Combinatorics LeetCode Problems
- Concurrency LeetCode Problems
- Counting LeetCode Problems
- Counting Sort LeetCode Problems
- Data Stream LeetCode Problems
- Database LeetCode Problems
- Depth-First Search LeetCode Problems
- Design LeetCode Problems