Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bdd342a

Browse files
committed
Add solution #2656
1 parent 562bdb2 commit bdd342a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,7 @@
19711971
2650|[Design Cancellable Function](./solutions/2650-design-cancellable-function.js)|Hard|
19721972
2651|[Calculate Delayed Arrival Time](./solutions/2651-calculate-delayed-arrival-time.js)|Easy|
19731973
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|
19741975
2657|[Find the Prefix Common Array of Two Arrays](./solutions/2657-find-the-prefix-common-array-of-two-arrays.js)|Medium|
19751976
2658|[Maximum Number of Fish in a Grid](./solutions/2658-maximum-number-of-fish-in-a-grid.js)|Medium|
19761977
2661|[First Completely Painted Row or Column](./solutions/2661-first-completely-painted-row-or-column.js)|Medium|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
};

0 commit comments

Comments
 (0)