Skip to content

Commit b7c895b

Browse files
authored
Create maximum-element-after-decreasing-and-rearranging.cpp
1 parent aa2722f commit b7c895b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(nlogn)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int maximumElementAfterDecrementingAndRearranging(vector<int>& arr) {
7+
sort(begin(arr), end(arr));
8+
int result = 1;
9+
for (int i = 1; i < size(arr); ++i) {
10+
result = min(result + 1, arr[i]);
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)