Greedy Problems
Master greedy problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 268 problems in this category.
Total Problems: 268
Easy: 36
Medium: 178
Hard: 54
Showing 50 of 268 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Greedy LeetCode Problems List
- 134. Gas Station - Medium - GreedyThere are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and i... Topics: Array, Greedy
- 55. Jump Game - Medium - GreedyYou are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum ju... Topics: Array, Dynamic Programming, Greedy
- 409. Longest Palindrome - Easy - GreedyGiven a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. L... Topics: Hash Table, String, Greedy
- 11. Container With Most Water - Medium - GreedyYou 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
- 179. Largest Number - Medium - GreedyGiven a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since the result may be very large, so ... Topics: Array, String, Greedy, Sorting
- 630. Course Schedule III - Hard - GreedyThere are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the i... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 122. Best Time to Buy and Sell Stock II - Medium - GreedyYou are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the... Topics: Array, Dynamic Programming, Greedy
- 621. Task Scheduler - Medium - GreedyYou are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of ... Topics: Array, Hash Table, Greedy, Sorting, Heap (Priority Queue), Counting
- 45. Jump Game II - Medium - GreedyYou are given a 0-indexed array of integers nums of length n. You are initially positioned at index 0. Each element nums[i] represents the maximum len... Topics: Array, Dynamic Programming, Greedy
- 680. Valid Palindrome II - Easy - GreedyGiven a string s, return true if the s can be palindrome after deleting at most one character from it.... Topics: Two Pointers, String, Greedy
- 1285. Balance a Binary Search Tree - Medium - GreedyGiven the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any o... Topics: Divide and Conquer, Greedy, Tree, Depth-First Search, Binary Search Tree, Binary Tree
- 420. Strong Password Checker - Hard - GreedyA password is considered strong if the below conditions are all met: It has at least 6 characters and at most 20 characters. It contains at least one ... Topics: String, Greedy, Heap (Priority Queue)
- 605. Can Place Flowers - Easy - GreedyYou have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an int... Topics: Array, Greedy
- 435. Non-overlapping Intervals - Medium - GreedyGiven an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest ... Topics: Array, Dynamic Programming, Greedy, Sorting
- 44. Wildcard Matching - Hard - GreedyGiven an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: '?' Matches any single character.... Topics: String, Dynamic Programming, Greedy, Recursion
- 316. Remove Duplicate Letters - Medium - GreedyGiven a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicogr... Topics: String, Stack, Greedy, Monotonic Stack
- 659. Split Array into Consecutive Subsequences - Medium - GreedyYou are given an integer array nums that is sorted in non-decreasing order. Determine if it is possible to split nums into one or more subsequences su... Topics: Array, Hash Table, Greedy, Heap (Priority Queue)
- 678. Valid Parenthesis String - Medium - GreedyGiven a string s containing only three types of characters: '(', ')' and '*', return true if s is valid. The following rules define a valid string: An... Topics: String, Dynamic Programming, Stack, Greedy
- 410. Split Array Largest Sum - Hard - GreedyGiven an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the... Topics: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum
- 1966. Frequency of the Most Frequent Element - Medium - GreedyThe frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you ... Topics: Array, Binary Search, Greedy, Sliding Window, Sorting, Prefix Sum
- 797. Rabbits in Forest - Medium - GreedyThere is a forest with an unknown number of rabbits. We asked n rabbits "How many rabbits have the same color as you?" and collected the answers in an... Topics: Array, Hash Table, Math, Greedy
- 2600. Maximum Tastiness of Candy Basket - Medium - GreedyYou are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k. The store sells baskets ... Topics: Array, Binary Search, Greedy, Sorting
- 714. Best Time to Buy and Sell Stock with Transaction Fee - Medium - GreedyYou are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee. Find th... Topics: Array, Dynamic Programming, Greedy
- 2362. Minimum Rounds to Complete All Tasks - Medium - GreedyYou are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3... Topics: Array, Hash Table, Greedy, Counting
- 1009. Pancake Sorting - Medium - GreedyGiven 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
- 770. Couples Holding Hands - Hard - GreedyThere are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where r... Topics: Greedy, Depth-First Search, Breadth-First Search, Union Find, Graph
- 768. Partition Labels - Medium - GreedyYou 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
- 1346. Maximize the Topmost Element After K Moves - Medium - GreedyYou are given a 0-indexed integer array nums representing the contents of a pile, where nums[0] is the topmost element of the pile. In one move, you c... Topics: Array, Greedy
- 1478. Maximum Number of Events That Can Be Attended - Medium - GreedyYou are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi. You can attend an even... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 324. Wiggle Sort II - Medium - GreedyGiven an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... You may assume the input array always has a valid answer.... Topics: Array, Divide and Conquer, Greedy, Sorting, Quickselect
- 581. Shortest Unsorted Continuous Subarray - Medium - GreedyGiven 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
- 3231. Minimum Number of Coins to be Added - Medium - GreedyYou are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target. An integer x is obtainable if th... Topics: Array, Greedy, Sorting
- 321. Create Maximum Number - Hard - GreedyYou 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
- 2032. Largest Odd Number in String - Easy - GreedyYou are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or... Topics: Math, String, Greedy
- 1448. Maximum 69 Number - Easy - GreedyYou are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes... Topics: Math, Greedy
- 2591. Frog Jump II - Medium - GreedyYou are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river. A frog, initially ... Topics: Array, Binary Search, Greedy
- 1033. Broken Calculator - Medium - GreedyThere is a broken calculator that has the integer startValue on its display initially. In one operation, you can: multiply the number on display by 2,... Topics: Math, Greedy
- 2248. Minimum Cost of Buying Candies With Discount - Easy - GreedyA shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free. The customer can choose any candy to take ... Topics: Array, Greedy, Sorting
- 2352. Design an ATM Machine - Medium - GreedyThere is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the ... Topics: Array, Greedy, Design
- 624. Maximum Distance in Arrays - Medium - GreedyYou are given m arrays, where each array is sorted in ascending order. You can pick up two integers from two different arrays (each array picks one) a... Topics: Array, Greedy
- 1304. Longest Happy String - Medium - GreedyA string s is called happy if it satisfies the following conditions: s only contains the letters 'a', 'b', and 'c'. s does not contain any of "aaa", "... Topics: String, Greedy, Heap (Priority Queue)
- 135. Candy - Hard - GreedyThere are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these chi... Topics: Array, Greedy
- 2488. Divide Intervals Into Minimum Number of Groups - Medium - GreedyYou 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
- 3743. Reschedule Meetings for Maximum Free Time I - Medium - GreedyYou are given an integer eventTime denoting the duration of an event, where the event occurs from time t = 0 to time t = eventTime. You are also given... Topics: Array, Greedy, Sliding Window
- 2690. House Robber IV - Medium - GreedyThere are several consecutive houses along a street, each of which has some money inside. There is also a robber, who wants to steal money from the ho... Topics: Array, Binary Search, Dynamic Programming, Greedy
- 957. Minimum Add to Make Parentheses Valid - Medium - GreedyA parentheses string is valid if and only if: It is the empty string, It can be written as AB (A concatenated with B), where A and B are valid strings... Topics: String, Stack, Greedy
- 452. Minimum Number of Arrows to Burst Balloons - Medium - GreedyThere are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where... Topics: Array, Greedy, Sorting
- 2725. Mice and Cheese - Medium - GreedyThere are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse. A point of the cheese with index i (0-in... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 3275. Minimum Number of Pushes to Type Word I - Easy - GreedyYou are given a string word containing distinct lowercase English letters. Telephone keypads have keys mapped with distinct collections of lowercase E... Topics: Math, String, Greedy
- 2475. Largest Palindromic Number - Medium - GreedyYou are given a string num consisting of digits only. Return the largest palindromic integer (in the form of a string) that can be formed using digits... Topics: Hash Table, String, Greedy, Counting
- 1139. Previous Permutation With One Swap - Medium - GreedyGiven an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that ca... Topics: Array, Greedy
- 1616. Minimum Difference Between Largest and Smallest Value in Three Moves - Medium - GreedyYou are given an integer array nums. In one move, you can choose one element of nums and change it to any value. Return the minimum difference between... Topics: Array, Greedy, Sorting
- 2670. Make K-Subarray Sums Equal - Medium - GreedyYou are given a 0-indexed integer array arr and an integer k. The array arr is circular. In other words, the first element of the array is the next el... Topics: Array, Math, Greedy, Sorting, Number Theory
- 1379. Reconstruct a 2-Row Binary Matrix - Medium - GreedyGiven the following details of a matrix with n columns and 2 rows : The matrix is a binary matrix, which means each element in the matrix can be 0 or ... Topics: Array, Greedy, Matrix
- 2279. Maximum Split of Positive Even Integers - Medium - GreedyYou are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers. For example, given finalSum = 12, the fol... Topics: Math, Backtracking, Greedy
- 1929. Maximum Value at a Given Index in a Bounded Array - Medium - GreedyYou are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions: ... Topics: Math, Binary Search, Greedy
- 2221. Check if a Parentheses String Can Be Valid - Medium - GreedyA parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true: It is (). It can be... Topics: String, Stack, Greedy
- 611. Valid Triangle Number - Medium - GreedyGiven 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
- 670. Maximum Swap - Medium - GreedyYou are given an integer num. You can swap two digits at most once to get the maximum valued number. Return the maximum valued number you can get.... Topics: Math, Greedy
- 1861. Building Boxes - Hard - GreedyYou have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where... Topics: Math, Binary Search, Greedy
- 2212. Removing Minimum and Maximum From Array - Medium - GreedyYou are given a 0-indexed array of distinct integers nums. There is an element in nums that has the lowest value and an element that has the highest v... Topics: Array, Greedy
- 1081. Video Stitching - Medium - GreedyYou are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have va... Topics: Array, Dynamic Programming, Greedy
- 1829. Maximum Units on a Truck - Easy - GreedyYou are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerB... Topics: Array, Greedy, Sorting
- 646. Maximum Length of Pair Chain - Medium - GreedyYou are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti. A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A... Topics: Array, Dynamic Programming, Greedy, Sorting
- 917. Boats to Save People - Medium - GreedyYou 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
- 2345. Minimum Number of Operations to Convert Time - Easy - GreedyYou are given two strings current and correct representing two 24-hour times. 24-hour times are formatted as "HH:MM", where HH is between 00 and 23, a... Topics: String, Greedy
- 3496. Minimum Number of Seconds to Make Mountain Height Zero - Medium - GreedyYou are given an integer mountainHeight denoting the height of a mountain. You are also given an integer array workerTimes representing the work time ... Topics: Array, Math, Binary Search, Greedy, Heap (Priority Queue)
- 2192. Minimum Cost Homecoming of a Robot in a Grid - Medium - GreedyThere is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where s... Topics: Array, Greedy
- 2559. Maximum Number of Non-overlapping Palindrome Substrings - Hard - GreedyYou 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
- 3620. Maximum Number of Distinct Elements After Operations - Medium - GreedyYou are given an integer array nums and an integer k. You are allowed to perform the following operation on each element of the array at most once: Ad... Topics: Array, Greedy, Sorting
- 2049. Eliminate Maximum Number of Monsters - Medium - GreedyYou are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, whe... Topics: Array, Greedy, Sorting
- 890. Lemonade Change - Easy - GreedyAt a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bill... Topics: Array, Greedy
- 402. Remove K Digits - Medium - GreedyGiven string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.... Topics: String, Stack, Greedy, Monotonic Stack
- 2756. Buy Two Chocolates - Easy - GreedyYou are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which repre... Topics: Array, Greedy, Sorting
- 2736. Minimum Additions to Make Valid String - Medium - GreedyGiven a string word to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must b... Topics: String, Dynamic Programming, Stack, Greedy
- 1499. Maximum Performance of a Team - Hard - GreedyYou are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] ... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 1648. Minimum Insertions to Balance a Parentheses String - Medium - GreedyGiven a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if: Any left parenthesis '(' must have a cor... Topics: String, Stack, Greedy
- 1018. Largest Perimeter Triangle - Easy - GreedyGiven an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible ... Topics: Array, Math, Greedy, Sorting
- 2245. Destroying Asteroids - Medium - GreedyYou are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is... Topics: Array, Greedy, Sorting
- 2616. Maximal Score After Applying K Operations - Medium - GreedyYou are given a 0-indexed integer array nums and an integer k. You have a starting score of 0. In one operation: choose an index i such that 0 <= i < ... Topics: Array, Greedy, Heap (Priority Queue)
- 2715. K Items With the Maximum Sum - Easy - GreedyThere is a bag that consists of items, each item has a number 1, 0, or -1 written on it. You are given four non-negative integers numOnes, numZeros, n... Topics: Math, Greedy
- 1711. Find Valid Matrix Given Row and Column Sums - Medium - GreedyYou are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum... Topics: Array, Greedy, Matrix
- 1529. Max Difference You Can Get From Changing an Integer - Medium - GreedyYou are given an integer num. You will apply the following steps to num two separate times: Pick a digit x (0 <= x <= 9). Pick another digit y (0 <= y... Topics: Math, Greedy
- 3770. Lexicographically Smallest Generated String - Hard - GreedyYou are given two strings, str1 and str2, of lengths n and m, respectively. A string word of length n + m - 1 is defined to be generated by str1 and s... Topics: String, Greedy, String Matching
- 1095. Two City Scheduling - Medium - GreedyA company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is ... Topics: Array, Greedy, Sorting
- 2123. The Number of Weak Characters in the Game - Medium - GreedyYou are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D i... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 2636. Maximum Subsequence Score - Medium - GreedyYou are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from n... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 502. IPO - Hard - GreedySuppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Capital, LeetCode would like to work on some projects... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 891. Score After Flipping Matrix - Medium - GreedyYou are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing... Topics: Array, Greedy, Bit Manipulation, Matrix
- 3741. Reschedule Meetings for Maximum Free Time II - Medium - GreedyYou are given an integer eventTime denoting the duration of an event. You are also given two integer arrays startTime and endTime, each of length n. T... Topics: Array, Greedy, Enumeration
- 1880. Largest Merge Of Two Strings - Medium - GreedyYou 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
- 632. Smallest Range Covering Elements from K Lists - Hard - GreedyYou have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists. We de... Topics: Array, Hash Table, Greedy, Sliding Window, Sorting, Heap (Priority Queue)
- 2088. Minimum Time to Type Word Using Special Typewriter - Easy - GreedyThere is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the poin... Topics: String, Greedy
- 2140. Longest Subsequence Repeated k Times - Hard - GreedyYou are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s. A subsequence is ... Topics: String, Backtracking, Greedy, Counting, Enumeration
- 2039. Sum Game - Medium - GreedyAlice and Bob take turns playing a game, with Alice starting first. You are given a string num of even length consisting of digits and '?' characters.... Topics: Math, String, Greedy, Game Theory
- 2156. Stone Game IX - Medium - GreedyAlice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array sto... Topics: Array, Math, Greedy, Counting, Game Theory
- 1710. Find Servers That Handled Most Number of Requests - Hard - GreedyYou have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capac... Topics: Array, Greedy, Heap (Priority Queue), Ordered Set
- 876. Hand of Straights - Medium - GreedyAlice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize con... Topics: Array, Hash Table, Greedy, Sorting
- 3948. Maximum Number of Subsequences After One Inserting - Medium - GreedyYou are given a string s consisting of uppercase English letters. You are allowed to insert at most one uppercase English letter at any position (incl... Topics: String, Dynamic Programming, Greedy, Prefix Sum
- 2590. Maximum Star Sum of a Graph - Medium - GreedyThere is an undirected graph consisting of n nodes numbered from 0 to n - 1. You are given a 0-indexed integer array vals of length n where vals[i] de... Topics: Array, Greedy, Graph, Sorting, Heap (Priority Queue)
- 1356. Minimum Number of Moves to Make Palindrome - Hard - GreedyYou 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
- 2664. Maximize Greatness of an Array - Medium - GreedyYou 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 - GreedyYou 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
- 1771. Sell Diminishing-Valued Colored Balls - Medium - GreedyYou have an inventory of different colored balls, and there is a customer that wants orders balls of any color. The customer weirdly values the colore... Topics: Array, Math, Binary Search, Greedy, Sorting, Heap (Priority Queue)
- 1515. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K - Medium - GreedyGiven an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times. The ... Topics: Math, Greedy
- 455. Assign Cookies - Easy - GreedyAssume 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
- 3712. Minimum Cost to Make Arrays Identical - Medium - GreedyYou are given two integer arrays arr and brr of length n, and an integer k. You can perform the following operations on arr any number of times: Split... Topics: Array, Greedy, Sorting
- 2117. Find Original Array From Doubled Array - Medium - GreedyAn integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shu... Topics: Array, Hash Table, Greedy, Sorting
- 3959. Maximum Total from Optimal Activation Order - Medium - GreedyYou 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)
- 2572. Append Characters to String to Make Subsequence - Medium - GreedyYou 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 - GreedyYou 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
- 3531. Minimum Amount of Damage Dealt to Bob - Hard - GreedyYou are given an integer power and two integer arrays damage and health, both having length n. Bob has n enemies, where enemy i will deal Bob damage[i... Topics: Array, Greedy, Sorting
- 3241. Divide Array Into Arrays With Max Difference - Medium - GreedyYou are given an integer array nums of size n where n is a multiple of 3 and a positive integer k. Divide the array nums into n / 3 arrays of size 3 s... Topics: Array, Greedy, Sorting
- 2650. Split With Minimum Sum - Easy - GreedyGiven a positive integer num, split it into two non-negative integers num1 and num2 such that: The concatenation of num1 and num2 is a permutation of ... Topics: Math, Greedy, Sorting
- 2681. Put Marbles in Bags - Hard - GreedyYou have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k. D... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 2289. Minimum Operations to Make the Array Alternating - Medium - GreedyYou are given a 0-indexed array nums consisting of n positive integers. The array nums is called alternating if: nums[i - 2] == nums[i], where 2 <= i ... Topics: Array, Hash Table, Greedy, Counting
- 2539. Minimum Number of Operations to Make Arrays Similar - Hard - GreedyYou are given two positive integer arrays nums and target, of the same length. In one operation, you can choose any two distinct indices i and j where... Topics: Array, Greedy, Sorting
- 3882. Partition Array for Maximum XOR and AND - Hard - GreedyYou are given an integer array nums. Partition the array into three (possibly empty) subsequences A, B, and C such that every element of nums belongs ... Topics: Array, Math, Greedy, Enumeration
- 1824. Maximum Number of Eaten Apples - Medium - GreedyThere is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days... Topics: Array, Greedy, Heap (Priority Queue)
- 2497. Maximum Matching of Players With Trainers - Medium - GreedyYou 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
- 3494. Minimum Cost for Cutting Cake I - Medium - GreedyThere is an m x n cake that needs to be cut into 1 x 1 pieces. You are given integers m, n, and two arrays: horizontalCut of size m - 1, where horizon... Topics: Array, Dynamic Programming, Greedy, Sorting
- 2450. Minimum Replacements to Sort the Array - Hard - GreedyYou are given a 0-indexed integer array nums. In one operation you can replace any element of the array with any two elements that sum to it. For exam... Topics: Array, Math, Greedy
- 1952. Minimum Sideway Jumps - Medium - GreedyThere is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to... Topics: Array, Dynamic Programming, Greedy
- 1451. Minimum Number of Taps to Open to Water a Garden - Hard - GreedyThere is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the length of the garden is n). Ther... Topics: Array, Dynamic Programming, Greedy
- 853. Most Profit Assigning Work - Medium - GreedyYou 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
- 2026. Merge Triplets to Form Target Triplet - Medium - GreedyA triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You ar... Topics: Array, Greedy
- 2877. Shortest String That Contains Three Strings - Medium - GreedyGiven three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings. If there are ... Topics: String, Greedy, Enumeration
- 3788. Maximum Unique Subarray Sum After Deletion - Easy - GreedyYou are given an integer array nums. You are allowed to delete any number of elements from nums without making it empty. After performing the deletion... Topics: Array, Hash Table, Greedy
- 649. Dota2 Senate - Medium - GreedyIn the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of senators coming from two parties. Now the Senate ... Topics: String, Greedy, Queue
- 1700. Minimum Time to Make Rope Colorful - Medium - GreedyAlice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope... Topics: Array, String, Dynamic Programming, Greedy
- 1519. Minimum Subsequence in Non-Increasing Order - Easy - GreedyGiven the array nums, obtain a subsequence of the array whose sum of elements is strictly greater than the sum of the non included elements in such su... Topics: Array, Greedy, Sorting
- 1303. Minimum Moves to Reach Target Score - Medium - GreedyYou are playing a game with integers. You start with the integer 1 and you want to reach the integer target. In one move, you can either: Increment th... Topics: Math, Greedy
- 2395. Longest Binary Subsequence Less Than or Equal to K - Medium - GreedyYou are given a binary string s and a positive integer k. Return the length of the longest subsequence of s that makes up a binary number less than or... Topics: String, Dynamic Programming, Greedy, Memoization
- 3868. Find Maximum Area of a Triangle - Medium - GreedyYou are given a 2D array coords of size n x 2, representing the coordinates of n points in an infinite Cartesian plane. Find twice the maximum area of... Topics: Array, Hash Table, Math, Greedy, Geometry, Enumeration
- 1766. Minimum Number of Removals to Make Mountain Array - Hard - GreedyYou 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, Binary Search, Dynamic Programming, Greedy
- 1341. Split a String in Balanced Strings - Easy - GreedyBalanced strings are those that have an equal quantity of 'L' and 'R' characters. Given a balanced string s, split it into some number of substrings s... Topics: String, Greedy, Counting
- 3195. Separate Black and White Balls - Medium - GreedyThere 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 - GreedyYou 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
- 2305. Append K Integers With Minimal Sum - Medium - GreedyYou are given an integer array nums and an integer k. Append k unique positive integers that do not appear in nums to nums such that the resulting tot... Topics: Array, Math, Greedy, Sorting
- 3552. Find the Largest Palindrome Divisible by K - Hard - GreedyYou are given two positive integers n and k. An integer x is called k-palindromic if: x is a palindrome. x is divisible by k. Return the largest integ... Topics: Math, String, Dynamic Programming, Greedy, Number Theory
- 1633. Minimum Number of Increments on Subarrays to Form a Target Array - Hard - GreedyYou are given an integer array target. You have an integer array initial of the same size as target with all elements initially zeros. In one operatio... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 2149. Remove Colored Pieces if Both Neighbors are the Same Color - Medium - GreedyThere are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is... Topics: Math, String, Greedy, Game Theory
- 3262. Find Polygon With the Largest Perimeter - Medium - GreedyYou are given an array of positive integers nums of length n. A polygon is a closed plane figure that has at least 3 sides. The longest side of a poly... Topics: Array, Greedy, Sorting, Prefix Sum
- 1690. Maximum Length of Subarray With Positive Product - Medium - GreedyGiven an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a ... Topics: Array, Dynamic Programming, Greedy
- 979. DI String Match - Easy - GreedyA 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
- 902. Minimum Number of Refueling Stops - Hard - GreedyA car travels from a starting position to a destination which is target miles east of the starting position. There are gas stations along the way. The... Topics: Array, Dynamic Programming, Greedy, Heap (Priority Queue)
- 3965. Earliest Finish Time for Land and Water Rides I - Easy - GreedyYou 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
- 2309. Maximize Number of Subsequences in a String - Medium - GreedyYou are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You c... Topics: String, Greedy, Prefix Sum
- 2237. Longest Palindrome by Concatenating Two Letter Words - Medium - GreedyYou are given an array of strings words. Each element of words consists of two lowercase English letters. Create the longest possible palindrome by se... Topics: Array, Hash Table, String, Greedy, Counting
- 2754. Maximum Strength of a Group - Medium - GreedyYou are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of stud... Topics: Array, Dynamic Programming, Backtracking, Greedy, Bit Manipulation, Sorting, Enumeration
- 2708. Find the String with LCP - Hard - GreedyWe define the lcp matrix of any 0-indexed string word of n lowercase English letters as an n x n grid such that: lcp[i][j] is equal to the length of t... Topics: Array, String, Dynamic Programming, Greedy, Union Find, Matrix
- 1762. Furthest Building You Can Reach - Medium - GreedyYou are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 an... Topics: Array, Greedy, Heap (Priority Queue)
- 3876. Transform Array to All Equal Elements - Medium - GreedyYou are given an integer array nums of size n containing only 1 and -1, and an integer k. You can perform the following operation at most k times: Cho... Topics: Array, Greedy
- 3334. Apple Redistribution into Boxes - Easy - GreedyYou are given an array apple of size n and an array capacity of size m. There are n packs where the ith pack contains apple[i] apples. There are m box... Topics: Array, Greedy, Sorting
- 2592. Minimum Total Cost to Make Arrays Unequal - Hard - GreedyYou are given two 0-indexed integer arrays nums1 and nums2, of equal length n. In one operation, you can swap the values of any two indices of nums1. ... Topics: Array, Hash Table, Greedy, Counting
- 3920. Minimum Stability Factor of Array - Hard - GreedyYou are given an integer array nums and an integer maxC. A subarray is called stable if the highest common factor (HCF) of all its elements is greater... Topics: Array, Math, Binary Search, Greedy, Segment Tree, Number Theory
- 1530. Check If a String Can Break Another String - Medium - GreedyGiven two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. In othe... Topics: String, Greedy, Sorting
- 3647. Zero Array Transformation III - Medium - GreedyYou are given an integer array nums of length n and a 2D array queries where queries[i] = [li, ri]. Each queries[i] represents the following action on... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Prefix Sum
- 334. Increasing Triplet Subsequence - Medium - GreedyGiven an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such... Topics: Array, Greedy
- 887. Minimum Cost to Hire K Workers - Hard - GreedyThere are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wa... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 1329. Minimum Cost to Move Chips to The Same Position - Easy - GreedyWe have n chips, where the position of the ith chip is position[i]. We need to move all the chips to the same position. In one step, we can change the... Topics: Array, Math, Greedy
- 2436. Make Array Zero by Subtracting Equal Amounts - Easy - GreedyYou are given a non-negative integer array nums. In one operation, you must: Choose a positive integer x such that x is less than or equal to the smal... Topics: Array, Hash Table, Greedy, Sorting, Heap (Priority Queue), Simulation
- 2640. Maximum Number of Integers to Choose From a Range I - Medium - GreedyYou are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules: The chosen in... Topics: Array, Hash Table, Binary Search, Greedy, Sorting
- 1049. Minimum Domino Rotations For Equal Row - Medium - GreedyIn a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 -... Topics: Array, Greedy
- 2765. Make Array Empty - Hard - GreedyYou are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty: If the first e... Topics: Array, Binary Search, Greedy, Binary Indexed Tree, Segment Tree, Sorting, Ordered Set
- 2412. Minimum Amount of Time to Fill Cups - Easy - GreedyYou have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or ... Topics: Array, Greedy, Sorting, Heap (Priority Queue)
- 2520. Using a Robot to Print the Lexicographically Smallest String - Medium - GreedyYou are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty: Remov... Topics: Hash Table, String, Stack, Greedy
- 2704. Maximum Difference by Remapping a Digit - Easy - GreedyYou are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit. Return the difference bet... Topics: Math, Greedy
- 3762. Maximize the Minimum Game Score - Hard - GreedyYou are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved... Topics: Array, Binary Search, Greedy
- 3904. Minimum Adjacent Swaps to Alternate Parity - Medium - GreedyYou are given an array nums of distinct integers. In one operation, you can swap any two adjacent elements in the array. An arrangement of the array i... Topics: Array, Greedy
- 3866. Minimum Steps to Convert String with Operations - Hard - GreedyYou are given two strings, word1 and word2, of equal length. You need to transform word1 into word2. For this, divide word1 into one or more contiguou... Topics: String, Dynamic Programming, Greedy
- 2337. Remove Digit From Number to Maximize Result - Easy - GreedyYou are given a string number representing a positive integer and a character digit. Return the resulting string after removing exactly one occurrence... Topics: String, Greedy, Enumeration
- 901. Advantage Shuffle - Medium - GreedyYou 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
- 1788. Stone Game VI - Medium - GreedyAlice and Bob take turns playing a game, with Alice starting first. There are n stones in a pile. On each player's turn, they can remove a stone from ... Topics: Array, Math, Greedy, Sorting, Heap (Priority Queue), Game Theory
- 3360. Minimum Deletions to Make String K-Special - Medium - GreedyYou are given a string word and an integer k. We consider word to be k-special if |freq(word[i]) - freq(word[j])| <= k for all indices i and j in the ... Topics: Hash Table, String, Greedy, Sorting, Counting
- 2084. Maximum Number of Weeks for Which You Can Work - Medium - GreedyThere are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the... Topics: Array, Greedy
- 2604. Minimum Operations to Make Array Equal II - Medium - GreedyYou are given two integer arrays nums1 and nums2 of equal length n and an integer k. You can perform the following operation on nums1: Choose two inde... Topics: Array, Math, Greedy
- 3107. Maximum Spending After Buying Items - Hard - GreedyYou are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items wh... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Matrix
- 1662. Minimum Numbers of Function Calls to Make Target Array - Medium - GreedyYou are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following ... Topics: Array, Greedy, Bit Manipulation
- 1047. Maximize Sum Of Array After K Negations - Easy - GreedyGiven an integer array nums and an integer k, modify the array in the following way: choose an index i and replace nums[i] with -nums[i]. You should a... Topics: Array, Greedy, Sorting
- 1858. Latest Time by Replacing Hidden Digits - Easy - GreedyYou are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?). The valid times are those inc... Topics: String, Greedy
- 2329. Maximum Product After K Increments - Medium - GreedyYou are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1. R... Topics: Array, Greedy, Heap (Priority Queue)
- 3390. Minimum Rectangles to Cover Points - Medium - GreedyYou are given a 2D integer array points, where points[i] = [xi, yi]. You are also given an integer w. Your task is to cover all the given points with ... Topics: Array, Greedy, Sorting
- 2710. Minimum Operations to Reduce an Integer to 0 - Medium - GreedyYou are given a positive integer n, you can do the following operation any number of times: Add or subtract a power of 2 from n. Return the minimum nu... Topics: Dynamic Programming, Greedy, Bit Manipulation
- 1502. Construct K Palindrome Strings - Medium - GreedyGiven a string s and an integer k, return true if you can use all the characters in s to construct non-empty k palindrome strings or false otherwise.... Topics: Hash Table, String, Greedy, Counting
- 3514. Shortest Distance After Road Addition Queries II - Hard - GreedyYou are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from... Topics: Array, Greedy, Graph, Ordered Set
- 3171. Minimum Equal Sum of Two Arrays After Replacing Zeros - Medium - GreedyYou are given two arrays nums1 and nums2 consisting of positive integers. You have to replace all the 0's in both arrays with strictly positive intege... Topics: Array, Greedy
- 1988. Minimize Maximum Pair Sum in Array - Medium - GreedyThe 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
- 991. Array of Doubled Pairs - Medium - GreedyGiven an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < l... Topics: Array, Hash Table, Greedy, Sorting
- 1961. Maximum Ice Cream Bars - Medium - GreedyIt is a sweltering summer day, and a boy wants to buy some ice cream bars. At the store, there are n ice cream bars. You are given an array costs of l... Topics: Array, Greedy, Sorting, Counting Sort
- 3894. Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values - Medium - GreedyYou are given two integer arrays x and y, each of length n. You must choose three distinct indices i, j, and k such that: x[i] != x[j] x[j] != x[k] x[... Topics: Array, Hash Table, Greedy, Sorting, Heap (Priority Queue)
- 779. Max Chunks To Make Sorted II - Hard - GreedyYou are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating ... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 2290. Removing Minimum Number of Magic Beans - Medium - GreedyYou are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag. Remove any... Topics: Array, Greedy, Sorting, Enumeration, Prefix Sum
- 738. Monotone Increasing Digits - Medium - GreedyAn integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y. Given an integer n, return the largest n... Topics: Math, Greedy
- 3445. Lexicographically Minimum String After Removing Stars - Medium - GreedyYou are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters. While there is a '*', do the followi... Topics: Hash Table, String, Stack, Greedy, Heap (Priority Queue)
- 2300. Construct String With Repeat Limit - Medium - GreedyYou are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears ... Topics: Hash Table, String, Greedy, Heap (Priority Queue), Counting
- 517. Super Washing Machines - Hard - GreedyYou have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 <=... Topics: Array, Greedy
- 3845. Maximum Sum of Edge Values in a Graph - Hard - GreedyYou are given an undirected connected graph of n nodes, numbered from 0 to n - 1. Each node is connected to at most 2 other nodes. The graph consists ... Topics: Math, Greedy, Graph
- 2720. Minimize the Maximum Difference of Pairs - Medium - GreedyYou are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs ... Topics: Array, Binary Search, Dynamic Programming, Greedy, Sorting
- 2469. Longest Subsequence With Limited Sum - Easy - GreedyYou are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the m... Topics: Array, Binary Search, Greedy, Sorting, Prefix Sum
- 780. Max Chunks To Make Sorted - Medium - GreedyYou are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of... Topics: Array, Stack, Greedy, Sorting, Monotonic Stack
- 3857. Find Maximum Number of Non Intersecting Substrings - Medium - GreedyYou are given a string word. Return the maximum number of non-intersecting substrings of word that are at least four characters long and start and end... Topics: Hash Table, String, Dynamic Programming, Greedy
- 2330. Maximum Total Beauty of the Gardens - Hard - GreedyAlice 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
- 778. Reorganize String - Medium - GreedyGiven a string s, rearrange the characters of s so that any two adjacent characters are not the same. Return any possible rearrangement of s or return... Topics: Hash Table, String, Greedy, Sorting, Heap (Priority Queue), Counting
- 1707. Check If String Is Transformable With Substring Sort Operations - Hard - GreedyGiven two strings s and t, transform string s into string t using the following operation any number of times: Choose a non-empty substring in s and s... Topics: String, Greedy, Sorting
- 1388. Greatest Sum Divisible by Three - Medium - GreedyGiven an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.... Topics: Array, Dynamic Programming, Greedy, Sorting
- 1355. Minimum Deletions to Make Array Beautiful - Medium - GreedyYou are given a 0-indexed integer array nums. The array nums is beautiful if: nums.length is even. nums[i] != nums[i + 1] for all i % 2 == 0. Note tha... Topics: Array, Stack, Greedy
- 2095. Minimum Number of Swaps to Make the String Balanced - Medium - GreedyYou 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
- 1629. Minimum Possible Integer After at Most K Adjacent Swaps On Digits - Hard - GreedyYou are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the in... Topics: String, Greedy, Binary Indexed Tree, Segment Tree
- 3025. Minimum Operations to Form Subsequence With Target Sum - Hard - GreedyYou are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target. In one operation, you must apply the following cha... Topics: Array, Greedy, Bit Manipulation
- 1464. Reduce Array Size to The Half - Medium - GreedyYou are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum... Topics: Array, Hash Table, Greedy, Sorting, Heap (Priority Queue)
- 1277. Largest Multiple of Three - Hard - GreedyGiven an array of digits digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. If th... Topics: Array, Math, Dynamic Programming, Greedy, Sorting
- 3954. Maximum Balanced Shipments - Medium - GreedyYou are given an integer array weight of length n, representing the weights of n parcels arranged in a straight line. A shipment is defined as a conti... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 3477. Minimum Operations to Make Binary Array Elements Equal to One II - Medium - GreedyYou are given a binary array nums. You can do the following operation on the array any number of times (possibly zero): Choose any index i from the ar... Topics: Array, Dynamic Programming, Greedy
- 2366. Maximum Bags With Full Capacity of Rocks - Medium - GreedyYou have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i]... Topics: Array, Greedy, Sorting
- 2530. Minimize Maximum of Array - Medium - GreedyYou are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: Choose an integer i such that 1 <= i < n and n... Topics: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum
- 3328. Apply Operations to Make Sum of Array Greater Than or Equal to k - Medium - GreedyYou are given a positive integer k. Initially, you have an array nums = [1]. You can perform any of the following operations on the array any number o... Topics: Math, Greedy, Enumeration
- 1659. Get the Maximum Score - Hard - GreedyYou 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
- 3151. Minimum Processing Time - Medium - GreedyYou have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors. Each task mus... Topics: Array, Greedy, Sorting
- 1062. Partition Array Into Three Parts With Equal Sum - Easy - GreedyGiven an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums. Formally, we can partition the a... Topics: Array, Greedy
- 1422. Divide Array in Sets of K Consecutive Numbers - Medium - GreedyGiven an array of integers nums and a positive integer k, check whether it is possible to divide this array into sets of k consecutive numbers. Return... Topics: Array, Hash Table, Greedy, Sorting
- 2487. Optimal Partition of String - Medium - GreedyGiven a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears i... Topics: Hash Table, String, Greedy
- 2689. Rearranging Fruits - Hard - GreedyYou have two fruit baskets containing n fruits each. You are given two 0-indexed integer arrays basket1 and basket2 representing the cost of fruit in ... Topics: Array, Hash Table, Greedy, Sort
- 3276. Minimum Number of Pushes to Type Word II - Medium - GreedyYou are given a string word containing lowercase English letters. Telephone keypads have keys mapped with distinct collections of lowercase English le... Topics: Hash Table, String, Greedy, Sorting, Counting
- 2191. Minimum Number of Food Buckets to Feed the Hamsters - Medium - GreedyYou are given a 0-indexed string hamsters where hamsters[i] is either: 'H' indicating that there is a hamster at index i, or '.' indicating that index... Topics: String, Dynamic Programming, Greedy
- 1489. Pizza With 3n Slices - Hard - GreedyThere is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows: You will pick any pizza slice. Your friend... Topics: Array, Dynamic Programming, Greedy, Heap (Priority Queue)
- 1994. Minimum Number of Swaps to Make the Binary String Alternating - Medium - GreedyGiven a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible. The string is called alternat... Topics: String, Greedy
- 3902. Maximize Spanning Tree Stability with Upgrades - Hard - GreedyYou are given an integer n, representing n nodes numbered from 0 to n - 1 and a list of edges, where edges[i] = [ui, vi, si, musti]: ui and vi indicat... Topics: Binary Search, Greedy, Union Find, Graph, Minimum Spanning Tree
- 1644. Maximum Number of Non-Overlapping Substrings - Hard - GreedyGiven a string s of lowercase letters, you need to find the maximum number of non-empty substrings of s that meet the following conditions: The substr... Topics: String, Greedy
- 3046. Minimum Operations to Make a Special Number - Medium - GreedyYou are given a 0-indexed string num representing a non-negative integer. In one operation, you can pick any digit of num and delete it. Note that if ... Topics: Math, String, Greedy, Enumeration
- 3485. Maximize Score of Numbers in Ranges - Medium - GreedyYou are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d]. You are asked to choose n integers where... Topics: Array, Binary Search, Greedy, Sorting
- 2538. Minimum Cost to Make Array Equal - Hard - GreedyYou are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: Incre... Topics: Array, Binary Search, Greedy, Sorting, Prefix Sum
- 3528. Reach End of Array With Max Score - Medium - GreedyYou are given an integer array nums of length n. Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than you... Topics: Array, Greedy
- 3766. Maximum Median Sum of Subsequences of Size 3 - Medium - GreedyYou are given an integer array nums with a length divisible by 3. You want to make the array empty in steps. In each step, you can select any three el... Topics: Array, Math, Greedy, Sorting, Game Theory
- 1649. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target - Medium - GreedyGiven an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarr... Topics: Array, Hash Table, Greedy, Prefix Sum
- 1652. Minimum Suffix Flips - Medium - GreedyYou are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want ... Topics: String, Greedy
- 1487. Cinema Seat Allocation - Medium - GreedyA cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above. Given the ... Topics: Array, Hash Table, Greedy, Bit Manipulation
- 2199. Two Furthest Houses With Different Colors - Easy - GreedyThere are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, w... Topics: Array, Greedy
- 2663. Distribute Money to Maximum Children - Easy - GreedyYou are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children th... Topics: Math, Greedy
- 1770. Minimum Deletions to Make Character Frequencies Unique - Medium - GreedyA string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of c... Topics: Hash Table, String, Greedy, Sorting
- 2379. Maximum Total Importance of Roads - Medium - GreedyYou are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1. You are also given a 2D integer array ... Topics: Greedy, Graph, Sorting, Heap (Priority Queue)
- 2100. Minimum Non-Zero Product of the Array Elements - Medium - GreedyYou are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2p - 1] in their binar... Topics: Math, Greedy, Recursion
- 2257. Earliest Possible Day of Full Bloom - Hard - GreedyYou have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth o... Topics: Array, Greedy, Sorting
- 1818. Maximum Score From Removing Substrings - Medium - GreedyYou are given a string s and two integers x and y. You can perform two types of operations any number of times. Remove substring "ab" and gain x point... Topics: String, Stack, Greedy
- 2418. Minimum Sum of Squared Difference - Medium - GreedyYou are given two positive 0-indexed integer arrays nums1 and nums2, both of length n. The sum of squared difference of arrays nums1 and nums2 is defi... Topics: Array, Binary Search, Greedy, Sorting, Heap (Priority Queue)
- 1228. Minimum Cost Tree From Leaf Values - Medium - GreedyGiven an array arr of positive integers, consider all binary trees such that: Each node has either 0 or 2 children; The values of arr correspond to th... Topics: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
- 2089. Maximum Matrix Sum - Medium - GreedyYou are given an n x n integer matrix. You can do the following operation any number of times: Choose any two adjacent elements of matrix and multiply... Topics: Array, Greedy, Matrix
- 561. Array Partition - Easy - GreedyGiven an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for a... Topics: Array, Greedy, Sorting, Counting Sort
- 1159. Smallest Subsequence of Distinct Characters - Medium - GreedyGiven a string s, return the lexicographically smallest subsequence of s that contains all the distinct characters of s exactly once.... Topics: String, Stack, Greedy, Monotonic Stack
- 2359. Maximum White Tiles Covered by a Carpet - Medium - GreedyYou are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white. You are als... Topics: Array, Binary Search, Greedy, Sliding Window, Sorting, Prefix Sum
- 2712. Find the Maximum Number of Marked Indices - Medium - GreedyYou 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
- 1252. Break a Palindrome - Medium - GreedyGiven a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the result... Topics: String, Greedy
- 2188. Minimized Maximum of Products Distributed to Any Store - Medium - GreedyYou are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexe... Topics: Array, Binary Search, Greedy
- 3764. Maximum Sum With at Most K Elements - Medium - GreedyYou are given a 2D integer matrix grid of size n x m, an integer array limits of length n, and an integer k. The task is to find the maximum sum of at... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Matrix
- 973. Stamping The Sequence - Hard - GreedyYou are given two strings stamp and target. Initially, there is a string s of length target.length with all s[i] == '?'. In one turn, you can place st... Topics: String, Stack, Greedy, Queue
- 2157. Smallest K-Length Subsequence With Occurrences of a Letter - Hard - GreedyYou are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length k... Topics: String, Stack, Greedy, Monotonic Stack
- 2387. Partition Array Such That Maximum Difference Is K - Medium - GreedyYou are given an integer array nums and an integer k. You may partition nums into one or more subsequences such that each element in nums appears in e... Topics: Array, Greedy, Sorting
- 1612. Avoid Flood in The City - Medium - GreedyYour country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of wa... Topics: Array, Hash Table, Binary Search, Greedy, Heap (Priority Queue)
- 3510. Maximize the Total Height of Unique Towers - Medium - GreedyYou are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the ith tower can be assigned. Your task is to assign a height... Topics: Array, Greedy, Sorting
- 2716. Prime Subtraction Operation - Medium - GreedyYou are given a 0-indexed integer array nums of length n. You can perform the following operation as many times as you want: Pick an index i that you ... Topics: Array, Math, Binary Search, Greedy, Number Theory
- 3607. Minimum Division Operations to Make Array Non Decreasing - Medium - GreedyYou are given an integer array nums. Any positive divisor of a natural number x that is strictly less than x is called a proper divisor of x. For exam... Topics: Array, Math, Greedy, Number Theory
- 2148. Minimum Number of Moves to Seat Everyone - Easy - GreedyThere are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat... Topics: Array, Greedy, Sorting, Counting Sort
- 1804. Maximum Binary String After Change - Medium - GreedyYou are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times: Operation 1: I... Topics: String, Greedy
- 330. Patching Array - Hard - GreedyGiven a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed b... Topics: Array, Greedy
- 376. Wiggle Subsequence - Medium - GreedyA wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first differenc... Topics: Array, Dynamic Programming, Greedy
- 1407. Group the People Given the Group Size They Belong To - Medium - GreedyThere are n people that are split into some unknown number of groups. Each person is labeled with a unique ID from 0 to n - 1. You are given an intege... Topics: Array, Hash Table, Greedy
- 825. Max Increase to Keep City Skyline - Medium - GreedyThere is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n... Topics: Array, Greedy, Matrix
- 2661. Smallest Missing Non-negative Integer After Operations - Medium - GreedyYou are given a 0-indexed integer array nums and an integer value. In one operation, you can add or subtract value from any element of nums. For examp... Topics: Array, Hash Table, Math, Greedy
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