Leetcode Problem 1846. Maximum Element After Decreasing and Rearranging

1846. Maximum Element After Decreasing and Rearranging

Leetcode Solutions

Greedy Approach with Sorting

  1. Sort the array in ascending order.
  2. Initialize the answer ans to 1, since the first element must be 1.
  3. Iterate over the array starting from the second element.
  4. For each element, if it is greater than or equal to ans + 1, increment ans by 1.
  5. Return the final value of ans.
UML Thumbnail

Counting Sort Inspired Approach

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...