File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1971
1971
2650|[ Design Cancellable Function] ( ./solutions/2650-design-cancellable-function.js ) |Hard|
1972
1972
2651|[ Calculate Delayed Arrival Time] ( ./solutions/2651-calculate-delayed-arrival-time.js ) |Easy|
1973
1973
2652|[ Sum Multiples] ( ./solutions/2652-sum-multiples.js ) |Easy|
1974
+ 2656|[ Maximum Sum With Exactly K Elements] ( ./solutions/2656-maximum-sum-with-exactly-k-elements.js ) |Easy|
1974
1975
2657|[ Find the Prefix Common Array of Two Arrays] ( ./solutions/2657-find-the-prefix-common-array-of-two-arrays.js ) |Medium|
1975
1976
2658|[ Maximum Number of Fish in a Grid] ( ./solutions/2658-maximum-number-of-fish-in-a-grid.js ) |Medium|
1976
1977
2661|[ First Completely Painted Row or Column] ( ./solutions/2661-first-completely-painted-row-or-column.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2656. Maximum Sum With Exactly K Elements
3
+ * https://leetcode.com/problems/maximum-sum-with-exactly-k-elements/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given a 0-indexed integer array nums and an integer k. Your task is to perform
7
+ * the following operation exactly k times in order to maximize your score:
8
+ * 1. Select an element m from nums.
9
+ * 2. Remove the selected element m from the array.
10
+ * 3. Add a new element with a value of m + 1 to the array.
11
+ * 4. Increase your score by m.
12
+ *
13
+ * Return the maximum score you can achieve after performing the operation exactly k times.
14
+ */
15
+
16
+ /**
17
+ * @param {number[] } nums
18
+ * @param {number } k
19
+ * @return {number }
20
+ */
21
+ var maximizeSum = function ( nums , k ) {
22
+ return k * Math . max ( ...nums ) + k * ( k - 1 ) / 2 ;
23
+ } ;
You can’t perform that action at this time.
0 commit comments