We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 89f257f commit b9ae329Copy full SHA for b9ae329
C++/maximum-sum-with-exactly-k-elements.cpp
@@ -0,0 +1,10 @@
1
+// Time: O(n)
2
+// Space: O(1)
3
+
4
+// math
5
+class Solution {
6
+public:
7
+ int maximizeSum(vector<int>& nums, int k) {
8
+ return *max_element(cbegin(nums), cend(nums)) * k + k * (k - 1) / 2;
9
+ }
10
+};
0 commit comments