DSAWiser

DSA question set · 197 questions

Greedy DSA Practice Questions

Explore 197 DSA questions in Greedy. Practice with DSAWiser’s code editor and visualizer.

GreedyMathStringsArraysSortingTwo PointersHeap (Priority Queue)StackCountingHash TableDynamic ProgrammingBinary Indexed TreeMonotonic StackSliding WindowBinary SearchQueueUnion FindGraphMatrix

What’s in this set

The Greedy collection contains 197 problems: 50 basic, 52 easy, 54 medium, 21 hard, 20 very hard. Choose a question at your current level, or follow the collection’s order below.

Topics in this collection include Greedy, Math, Strings, Arrays, Sorting. Each question shows its own topics and difficulty so you can decide where to begin.

Practice with the code visualizer

  1. Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
  2. Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
  3. Step through your code in the visualizer. Use a breakpoint to inspect the state at a specific line, then compare it with your reasoning.

Questions in this set

197 total

Open a question in the editor to read its statement and examples. Sign in to practice.

  1. Larger of Two NumbersGreedy · MathBasic
  2. Cheaper of Two PricesGreedy · MathBasic
  3. Enough Money?Greedy · MathBasic
  4. Pick the Bigger GiftGreedy · StringsBasic
  5. Match WinnerGreedy · StringsBasic
  6. Height LimitGreedy · MathBasic
  7. One BonusGreedy · MathBasic
  8. Repeated Better OptionGreedy · MathBasic
  9. Heavier BasketGreedy · ArraysBasic
  10. Discount PriceMathBasic
  11. Coins of 1, 2 and 5Greedy · MathBasic
  12. Coins of 1, 5, 10 and 25Greedy · MathBasic
  13. Count Every CoinGreedy · Math · ArraysBasic
  14. Banknotes of 1, 5, 10, 50 and 100Greedy · MathBasic
  15. Take While You CanGreedy · ArraysBasic
  16. Counting Sock PairsArrays · MathBasic
  17. Same-Price CandiesGreedy · MathBasic
  18. Largest Number from DigitsGreedy · Sorting · MathBasic
  19. Smallest Number from DigitsGreedy · Sorting · MathBasic
  20. Climbing Stairs (1 or 2)Greedy · MathBasic
  21. Frog Jumps (1, 2 or 3)Greedy · MathBasic
  22. Weekly SavingsGreedy · ArraysBasic
  23. Sticker AlternationGreedy · ArraysBasic
  24. Rope PiecesGreedy · MathBasic
  25. Two Items, One BudgetGreedy · MathBasic
  26. Maximum of the ListArraysBasic
  27. Minimum of the ListArraysBasic
  28. Record-Breaking DaysArraysBasic
  29. Hotter Than YesterdayArraysBasic
  30. Longest Same-Value StretchArraysBasic
  31. Longest Warm StretchGreedy · ArraysBasic
  32. Always the Better OptionGreedy · ArraysBasic
  33. Range of the ListArraysBasic
  34. Peaks in the RowArraysBasic
  35. Increasing PrefixArraysBasic
  36. Best Trade DayGreedy · ArraysBasic
  37. Longest Run of Even NumbersArraysBasic
  38. Best Pair of NeighborsGreedy · ArraysBasic
  39. Score Reset GameGreedy · ArraysBasic
  40. Safe SpendingGreedy · ArraysBasic
  41. Order Two TasksGreedy · MathBasic
  42. Merge Two Sorted ListsTwo Pointers · ArraysBasic
  43. Sum of the k LargestGreedy · Sorting · ArraysBasic
  44. Cheapest PairGreedy · ArraysBasic
  45. Both Take the LargestGreedy · Sorting · ArraysBasic
  46. Two Boxes, First FitGreedy · ArraysBasic
  47. One Free PurchaseGreedy · ArraysBasic
  48. Watering the GardenGreedy · MathBasic
  49. Maximum ItemsGreedy · Sorting · ArraysBasic
  50. Take the Larger EndGreedy · Two Pointers · ArraysBasic
  51. Cookie GiveawayGreedy · Two Pointers · Arrays · SortingEasy
  52. Profit from Every RiseGreedy · ArraysEasy
  53. Lemonade StandGreedy · ArraysEasy
  54. Two Teams SplitGreedy · Sorting · ArraysEasy
  55. Rescue RaftsGreedy · Two Pointers · Arrays · SortingEasy
  56. Movie MarathonGreedy · Sorting · ArraysEasy
  57. One Screen, Few CancellationsGreedy · Sorting · ArraysEasy
  58. Shortest Job FirstGreedy · Sorting · ArraysEasy
  59. Tandem BicyclesGreedy · Sorting · ArraysEasy
  60. Pair and Sum the SmallerGreedy · Sorting · ArraysEasy
  61. Flower Bed SpacingGreedy · ArraysEasy
  62. Matching SeatsGreedy · Sorting · ArraysEasy
  63. Mice and HolesGreedy · Sorting · ArraysEasy
  64. Chocolate PacksGreedy · Sorting · ArraysEasy
  65. Buy Two ChocolatesGreedy · Sorting · ArraysEasy
  66. Largest Perimeter TriangleGreedy · Sorting · Arrays · MathEasy
  67. Sign FlipsGreedy · Sorting · ArraysEasy
  68. Up-Down SignatureGreedy · Two Pointers · Strings · ArraysEasy
  69. One Digit UpgradeGreedy · MathEasy
  70. Largest Odd Tail NumberGreedy · Strings · MathEasy
  71. Messy ColumnsGreedy · Arrays · StringsEasy
  72. Joining RopesGreedy · Heap (Priority Queue) · ArraysEasy
  73. Fractional LootGreedy · Sorting · ArraysEasy
  74. All Papers on TimeGreedy · Sorting · ArraysEasy
  75. Sorting by PiecesGreedy · ArraysEasy
  76. Pairs Under the LimitTwo Pointers · ArraysEasy
  77. Calm PartnersGreedy · Two Pointers · Sorting · ArraysEasy
  78. Just Enough Fuel StopsGreedy · ArraysEasy
  79. Fixing the BracketsGreedy · Strings · StackEasy
  80. Gathering the ChipsGreedy · Math · ArraysEasy
  81. Candy Shop OfferGreedy · Sorting · ArraysEasy
  82. Splitting a Balanced LineGreedy · Strings · CountingEasy
  83. Smallest RearrangementGreedy · Sorting · StringsEasy
  84. Alternating LightsGreedy · ArraysEasy
  85. Two Sum, SortedTwo Pointers · ArraysEasy
  86. One Calendar CheckGreedy · Sorting · ArraysEasy
  87. Largest Number from Length and SumGreedy · Math · StringsEasy
  88. Smallest Number from Length and SumGreedy · Math · StringsEasy
  89. Level the StepsGreedy · ArraysEasy
  90. Minimizing the Product SumGreedy · Sorting · ArraysEasy
  91. Trees with Elbow RoomGreedy · Sorting · ArraysEasy
  92. Take the Bigger HalfGreedy · Sorting · ArraysEasy
  93. Close PairsGreedy · Sorting · Two Pointers · ArraysEasy
  94. Zigzag OrderGreedy · Sorting · ArraysEasy
  95. Meet in the MiddleMath · Sorting · ArraysEasy
  96. Building the Longest PalindromeGreedy · Hash Table · StringsEasy
  97. Keep the Best of Each RunGreedy · Strings · ArraysEasy
  98. Jobs Before Their DeadlinesGreedy · Sorting · ArraysEasy
  99. Digits That Never FallGreedy · MathEasy
  100. Taxi FleetGreedy · Sorting · Two Pointers · ArraysEasy
  101. Rain BarrelsGreedy · Dynamic Programming · StringsEasy
  102. Three Piles of StonesGreedy · MathEasy
  103. Circular Fuel TourGreedy · ArraysMedium
  104. Can You Cross the Swamp?Greedy · Arrays · Dynamic ProgrammingMedium
  105. Text SegmentsGreedy · Two Pointers · Strings · Hash TableMedium
  106. Arrow RainGreedy · Sorting · ArraysMedium
  107. Task CooldownGreedy · Sorting · Counting · Hash TableMedium
  108. Fewest Jumps AcrossGreedy · Arrays · Dynamic ProgrammingMedium
  109. Queue ReformationGreedy · Binary Indexed Tree · Sorting · ArraysMedium
  110. Energy CardsGreedy · Two Pointers · Sorting · ArraysMedium
  111. Stitching the FilmGreedy · Dynamic Programming · ArraysMedium
  112. Biggest ConcatenationGreedy · Sorting · StringsMedium
  113. Runs of K CardsGreedy · Sorting · Arrays · Hash TableMedium
  114. No Double LettersGreedy · Heap (Priority Queue) · Strings · CountingMedium
  115. Fewest RoomsGreedy · Sorting · Heap (Priority Queue) · ArraysMedium
  116. Erase DigitsGreedy · Stack · Monotonic Stack · StringsMedium
  117. Bracket WildcardsGreedy · Strings · Dynamic Programming · StackMedium
  118. Rotate the DominoesGreedy · ArraysMedium
  119. Bus LoadGreedy · Arrays · SortingMedium
  120. Garden TapsGreedy · Dynamic Programming · ArraysMedium
  121. Clean CutsGreedy · Hash Table · StringsMedium
  122. Removing the RaritiesGreedy · Hash Table · Sorting · ArraysMedium
  123. Gathering the OnesGreedy · Sliding Window · ArraysMedium
  124. Ladders and BricksGreedy · Heap (Priority Queue) · ArraysMedium
  125. The Broken CalculatorGreedy · MathMedium
  126. One Swap WonderGreedy · MathMedium
  127. Best CrewGreedy · Sorting · ArraysMedium
  128. Trimming the EndsGreedy · Two Pointers · StringsMedium
  129. One Fix SortGreedy · ArraysMedium
  130. Splitting Into Even PartsGreedy · MathMedium
  131. Happiest DinersGreedy · Sorting · ArraysMedium
  132. Building the Target TripletGreedy · ArraysMedium
  133. Biggest Cake PieceSorting · ArraysMedium
  134. Prize SelectionGreedy · Hash Table · Sorting · ArraysMedium
  135. Pancake ChefGreedy · Two Pointers · Sorting · ArraysMedium
  136. Car ConvoysGreedy · Sorting · Arrays · Monotonic StackMedium
  137. Digit RiddleGreedy · Stack · StringsMedium
  138. Finish the ChantGreedy · StringsMedium
  139. Gift BasketsGreedy · Sorting · ArraysMedium
  140. Merge Time BlocksGreedy · Sorting · ArraysMedium
  141. Making Frequencies UniqueGreedy · Sorting · Strings · Hash TableMedium
  142. Strict Zigzag OrderGreedy · Sorting · ArraysMedium
  143. Scenic Photo PairGreedy · Arrays · Dynamic ProgrammingMedium
  144. Counting Positive PrefixesGreedy · Sorting · ArraysMedium
  145. Marking the IndicesGreedy · Two Pointers · Sorting · ArraysMedium
  146. Leveling the PeaksGreedy · ArraysMedium
  147. Marble BagsGreedy · Sorting · ArraysMedium
  148. Distant RepeatsGreedy · Heap (Priority Queue) · Strings · Hash TableMedium
  149. Task Reordering EnergyGreedy · Sorting · ArraysMedium
  150. Field BloomGreedy · Sorting · ArraysMedium
  151. Cake Cutting CostsGreedy · Sorting · ArraysMedium
  152. Largest Multiple of ThreeGreedy · Dynamic Programming · ArraysMedium
  153. Largest MergeGreedy · Two Pointers · StringsMedium
  154. Diminishing TreasureGreedy · Binary Search · Sorting · Arrays · MathMedium
  155. Fair Weighted LevellingGreedy · Binary Search · Sorting · ArraysMedium
  156. Longest Chunked PalindromeGreedy · Two Pointers · Dynamic Programming · StringsMedium
  157. Event MarathonGreedy · Heap (Priority Queue) · Arrays · SortingHard
  158. Course Deadline CrunchGreedy · Heap (Priority Queue) · Arrays · SortingHard
  159. Fuel RefitsGreedy · Heap (Priority Queue) · Arrays · Dynamic ProgrammingHard
  160. Team PerformanceGreedy · Heap (Priority Queue) · Arrays · SortingHard
  161. Venture CapitalGreedy · Heap (Priority Queue) · Arrays · SortingHard
  162. Money Before TradingGreedy · Sorting · ArraysHard
  163. Computer RuntimeGreedy · Binary Search · Arrays · SortingHard
  164. Value PatchingGreedy · ArraysHard
  165. K Consecutive FlipsGreedy · Queue · Sliding Window · ArraysHard
  166. Latest Possible TasksGreedy · Sorting · ArraysHard
  167. Smallest Range Across ListsGreedy · Heap (Priority Queue) · Sliding Window · ArraysHard
  168. Two Rows, One Giant NumberGreedy · Monotonic Stack · Stack · ArraysHard
  169. Digit RansomGreedy · Binary Indexed Tree · StringsHard
  170. Sorting by Pieces IIGreedy · Monotonic Stack · Sorting · ArraysHard
  171. Couples at the PartyGreedy · Union Find · Graph · ArraysHard
  172. Rearranging FruitsGreedy · Hash Table · Sorting · ArraysHard
  173. Palindrome by Adjacent SwapsGreedy · Two Pointers · Binary Indexed Tree · StringsHard
  174. Washers in a RowGreedy · ArraysHard
  175. Meeting Rooms, NumberedGreedy · Heap (Priority Queue) · Sorting · ArraysHard
  176. Best Meeting SquareSorting · Math · MatrixHard
  177. Fair BonusesGreedy · ArraysHard
  178. Raising the TerracesGreedy · ArraysVery hard
  179. Snapping the ReedsGreedy · Arrays · MathVery hard
  180. Voltage BandGreedy · Heap (Priority Queue) · ArraysVery hard
  181. Battery Chore QueueGreedy · Sorting · ArraysVery hard
  182. Reverse-Built WallGreedy · Heap (Priority Queue) · ArraysVery hard
  183. Elegant SouvenirsGreedy · Sorting · Heap (Priority Queue) · ArraysVery hard
  184. Wage-Fair CrewGreedy · Sorting · Heap (Priority Queue) · ArraysVery hard
  185. Twin WitnessesGreedy · Sorting · ArraysVery hard
  186. Shared Break WindowsGreedy · Sorting · ArraysVery hard
  187. Three-Way Sheet MergeGreedy · Heap (Priority Queue) · ArraysVery hard
  188. Two-Station AssemblyGreedy · Sorting · ArraysVery hard
  189. Cheapest Road NetworkGreedy · Union Find · Sorting · GraphVery hard
  190. Cheapest Delivery RouteGreedy · Heap (Priority Queue) · GraphVery hard
  191. Watchtowers in the CanopyGreedy · Graph · ArraysVery hard
  192. Busiest Delivery HallsGreedy · Heap (Priority Queue) · ArraysVery hard
  193. K Consecutive LanternsGreedy · Sliding Window · Math · ArraysVery hard
  194. Skyline of the Festival TentsGreedy · Heap (Priority Queue) · Sorting · ArraysVery hard
  195. Server Hall DispatchGreedy · Heap (Priority Queue) · ArraysVery hard
  196. Typeset the ScrollGreedy · Strings · ArraysVery hard
  197. Bracket Mountain PeaksGreedy · Strings · SortingVery hard