Premium Only Content
![2593. Find Score of an Array After Marking All Elements](https://1a-1791.com/video/s8/6/0/u/J/H/0uJHv.qR4e.jpg)
2593. Find Score of an Array After Marking All Elements
You are given an array nums consisting of positive integers.
Starting with score = 0, apply the following algorithm:
Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
Add the value of the chosen integer to score.
Mark the chosen element and its two adjacent elements if they exist.
Repeat until all the array elements are marked.
Return the score you get after applying the above algorithm.
Example 1:
Input: nums = [2,1,3,4,5,2]
Output: 7
Explanation: We mark the elements as follows:
- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,1,3,4,5,2].
- 2 is the smallest unmarked element, so we mark it and its left adjacent element: [2,1,3,4,5,2].
- 4 is the only remaining unmarked element, so we mark it: [2,1,3,4,5,2].
Our score is 1 + 2 + 4 = 7.
Example 2:
Input: nums = [2,3,5,1,3,2]
Output: 5
Explanation: We mark the elements as follows:
- 1 is the smallest unmarked element, so we mark it and its two adjacent elements: [2,3,5,1,3,2].
- 2 is the smallest unmarked element, since there are two of them, we choose the left-most one, so we mark the one at index 0 and its right adjacent element: [2,3,5,1,3,2].
- 2 is the only remaining unmarked element, so we mark it: [2,3,5,1,3,2].
Our score is 1 + 2 + 2 = 5.
Constraints:
1 <= nums.length <= 105
1 <= nums[i] <= 106
#define ll long long
class Solution {
public:
long long findScore(vector<int>& nums) {
ll score = 0;
int n = nums.size();
vector<pair<int,int>> vec;
unordered_map<int,int> mp;
for(int i=0; i<n; i++)
vec.push_back({nums[i], i});
sort(vec.begin(), vec.end());
for(int i=0; i<n; i++){
if(mp.find(vec[i].first) == mp.end() && nums[vec[i].second] != INT_MAX){
if(vec[i].second-1 >= 0) nums[vec[i].second - 1] = INT_MAX;
if(vec[i].second+1 < n) nums[vec[i].second + 1] = INT_MAX;
score += vec[i].first;
}
}
return score;
}
};
-
1:38:12
The Officer Tatum
2 hours agoLIVE Security Guard POWER SLAPS Black Woman as LEFTISTS Cry OVER RFK Jr. + More Ep 62
4.27K15 -
1:46:13
The Quartering
4 hours agoDOJ Employees QUIT, Mass Federal Layoffs Start, and Kanye Divorce Rumors
33.7K14 -
DVR
Dr. Eric Berg
4 days agoThe Dr. Berg Show LIVE February 14, 2025
6.29K2 -
40:17
SLS - Street League Skateboarding
1 day agoEVERY 9 CLUB IN FLORIDA! Looking back at SLS Jacksonville 2021 & 2022 - Yuto, Jagger, Sora & more...
2.99K -
48:05
Stephen Gardner
1 hour ago🔥IT'S OVER! Congress CAN'T HIDE this from Elon MUSK and Trump!!
3.43K11 -
1:01:47
Tucker Carlson
2 hours agoHungary Prime Minister Viktor Orban on USAID, Trump, Immigration, NATO, and the Russia/Ukraine War
79.3K37 -
1:32:52
Russell Brand
21 hours agoThe Battle for Truth: Gregg Hurwitz on Myth, Power & Cultural Control
86.7K4 -
1:56:59
The Charlie Kirk Show
3 hours agoVance Buries the Globalists + Inside DOGE + AMA | Dowd | 2.14.2025
118K15 -
2:15:50
Melonie Mac
3 hours agoTomb Raider the Angel of Darkness Remaster Stream!
15K4 -
LIVE
Major League Fishing
2 days agoLIVE! - Bass Pro Tour: Stage 2 - Day 2
484 watching