---
# System prepended metadata

title: 1846. Maximum Element After Decreasing and Rearranging
tags: [Leetcode, Medium, Greedy]

---

# 1846. Maximum Element After Decreasing and Rearranging
###### tags: `Leetcode` `Medium` `Greedy`
Link: https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging/description/
## Code
```java=
class Solution {
    public int maximumElementAfterDecrementingAndRearranging(int[] arr) {
        Arrays.sort(arr);
        arr[0] = 1;
        int n = arr.length;
        for(int i=1; i<n; i++){
            arr[i] = Math.min(arr[i-1]+1, arr[i]);
        }
        return arr[n-1];
    }
}
```