Leetcode Problem 1798. Maximum Number of Consecutive Values You Can Make

1798. Maximum Number of Consecutive Values You Can Make

Leetcode Solutions

Greedy Approach with Sorting

  1. Sort the array of coins in ascending order.
  2. Initialize a variable res to 1, which represents the next value we want to make.
  3. Iterate through the sorted coins array. a. If the current coin value a is greater than res, break the loop. b. If a is less than or equal to res, add a to res.
  4. Return res as the maximum number of consecutive integer values that can be made.
UML Thumbnail

Dynamic Programming Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...