> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/02-25-2022-1846.md).

# 02/25/2022 1846

Method：

Sort array first, set the first element = 1. If the next element is more than 1 greater then the previous one, set it to previous + 1. Finally return the last value.

Time O(nlogn)

Space O(1)

```
class Solution {
    public int maximumElementAfterDecrementingAndRearranging(int[] arr) {
        Arrays.sort(arr);
        arr[0] = 1;
        for(int i = 1; i < arr.length; i++) {
            if (arr[i] - arr[i-1] > 1) {
                arr[i] = arr[i-1] + 1;
            }
        }
        return arr[arr.length-1];
    }
}
```
