You are given an array of positive integers `arr`. You may rearrange the elements in any order and decrease any element to a smaller positive integer, as many times as you like. After that the array must satisfy: the first element is `1`, and every two adjacent elements differ by at most `1`. Return the largest possible value of the maximum element.
You are given an array of positive integers arr. You may rearrange the elements in any order and decrease any element to a smaller positive integer, as many times as you like. After that the array must satisfy: the first element is 1, and every two adjacent elements differ by at most 1. Return the largest possible value of the maximum element.
Example 1:
Input: {"arr":[2,2,1,2,1]}
Output: 2
Constraints:
1≤arr.length≤105
1≤arr[i]≤109
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[2,2,1,2,1]}
input arr (any order)
2
2
1
2
1
values as given
2
2
1
2
1
We get 5 values in any order. We may rearrange them and only ever decrease them, and the result must start at 1 and rise by at most 1 per step.