Greedy
Greedy
Fifty-five questions on greedy algorithms, where the locally optimal choice at each step leads to a globally optimal solution.
Apple Redistribution into Boxes
easyYou are given an array apple of size n and an array capacity of size m.
Array Partition
easyGiven 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 all i is maximized.
Assign Cookies
easyAssume you are an awesome parent and want to give your children some cookies.
Buy Two Chocolates
easyYou are given an integer array prices representing the prices of various chocolates in a store.
Can Place Flowers
easyYou have a long flowerbed in which some of the plots are planted, and some are not.
DI String Match
easyA 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: Given a string s, reconstruct the permutation perm...
Distribute Money to Maximum Children
easyYou are given an integer money denoting the amount of money (in dollars) that you have and another integer children denoting the number of children that you must distribute the...
K Items With the Maximum Sum
easyThere is a bag that consists of items, each item has a number 1, 0, or -1 written on it.
Largest Odd Number in String
easyYou are given a string num, representing a large integer.
Largest Perimeter Triangle
easyGiven an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths.
Latest Time by Replacing Hidden Digits
easyYou are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).
Lemonade Change
easyAt a lemonade stand, each lemonade costs $5.
Lexicographically Smallest Palindrome
easyYou are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it.
Lexicographically Smallest String After a Swap
easyGiven a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once.
Longest Palindrome
easyGiven a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.
Longest Subsequence With Limited Sum
easyYou are given an integer array nums of length n, and an integer array queries of length m.
Longest Unequal Adjacent Groups Subsequence I
easyYou are given a string array words and a binary array groups both of length n.
Make Array Zero by Subtracting Equal Amounts
easyYou are given a non-negative integer array nums.
Maximize Sum Of Array After K Negations
easyGiven an integer array nums and an integer k, modify the array in the following way: You should apply this process exactly k times.
Maximum 69 Number
easyYou are given a positive integer num consisting only of digits 6 and 9.
Maximum Difference by Remapping a Digit
easyYou are given an integer num.
Maximum Odd Binary Number
easyYou are given a binary string s that contains at least one '1'.
Maximum Sum With Exactly K Elements
easyYou are given a 0-indexed integer array nums and an integer k.
Maximum Unique Subarray Sum After Deletion
easyYou are given an integer array nums.
Maximum Units on a Truck
easyYou are assigned to put some amount of boxes onto one truck.
Minimum Amount of Time to Fill Cups
easyYou have a water dispenser that can dispense cold, warm, and hot water.
Minimum Cost of Buying Candies With Discount
easyA shop is selling candies at a discount.
Minimum Cost to Move Chips to The Same Position
easyWe have n chips, where the position of the ith chip is position[i].
Minimum Deletions for At Most K Distinct Characters
easyYou are given a string s consisting of lowercase English letters, and an integer k.
Minimum Hours of Training to Win a Competition
easyYou are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.
Minimum Moves to Convert String
easyYou are given a string s consisting of n characters which are either 'X' or 'O'.
Minimum Number of Moves to Seat Everyone
easyThere are n availabe seats and n students standing in a room.
Minimum Number of Operations to Convert Time
easyYou are given two strings current and correct representing two 24-hour times.
Minimum Number of Pushes to Type Word I
easyYou are given a string word containing distinct lowercase English letters.
Minimum Operations to Make the Array Increasing
easyYou are given an integer array nums (0-indexed).
Minimum Subsequence in Non-Increasing Order
easyGiven 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 subsequence.
Minimum Sum of Four Digit Number After Splitting Digits
easyYou are given a positive integer num consisting of exactly four digits.
Minimum Time to Type Word Using Special Typewriter
easyThere is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer.
Partition Array Into Three Parts With Equal Sum
easyGiven an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Remove Digit From Number to Maximize Result
easyYou are given a string number representing a positive integer and a character digit.
Split a String in Balanced Strings
easyBalanced strings are those that have an equal quantity of 'L' and 'R' characters.
Split With Minimum Sum
easyGiven a positive integer num, split it into two non-negative integers num1 and num2 such that: Return the minimum possible sum of num1 and num2.
Two Furthest Houses With Different Colors
easyThere are n houses evenly lined up on the street, and each house is beautifully painted.
Valid Palindrome II
easyGiven a string s, return true if the s can be palindrome after deleting at most one character from it.
Add Minimum Number of Rungs
mediumYou are given a strictly increasing integer array rungs that represents the height of rungs on a ladder.
Advantage Shuffle
mediumYou are given two integer arrays nums1 and nums2 both of the same length.
Append Characters to String to Make Subsequence
mediumYou are given two strings s and t consisting of only lowercase English letters.
Append K Integers With Minimal Sum
mediumYou are given an integer array nums and an integer k.
Apply Operations to Make Sum of Array Greater Than or Equal to k
mediumYou are given a positive integer k.
Array of Doubled Pairs
mediumGiven 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 < len(arr) / 2, or false...
Array With Elements Not Equal to Average of Neighbors
mediumYou are given a 0-indexed array nums of distinct integers.
Avoid Flood in The City
mediumYour country has an infinite number of lakes.
Bag of Tokens
mediumYou start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] denotes the value of tokeni.
Best Time to Buy and Sell Stock II
mediumYou are given an integer array prices where prices[i] is the price of a given stock on the ith day.
Best Time to Buy and Sell Stock with Transaction Fee
mediumYou 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.