Tap here to switch tabs
Problem
Submissions

Problem: Find Score of an Array After Marking All Elements

Try to solve the Find Score of an Array After Marking All Elements problem.

Statement

You are given an array nums consisting of positive integers.

Starting with an initial score of 00, process the array by repeatedly performing the following operations until all elements are marked:

11. Select the smallest unmarked integer in nums. If there is a tie, select the one with the smallest index.
22. Add the value of the chosen integer to your total score.
33. Mark the chosen element as well as its immediate left and right adjacent elements, if they exist.

Return the total score obtained after all elements in nums are marked.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Score of an Array After Marking All Elements

Try to solve the Find Score of an Array After Marking All Elements problem.

Statement

You are given an array nums consisting of positive integers.

Starting with an initial score of 00, process the array by repeatedly performing the following operations until all elements are marked:

11. Select the smallest unmarked integer in nums. If there is a tie, select the one with the smallest index.
22. Add the value of the chosen integer to your total score.
33. Mark the chosen element as well as its immediate left and right adjacent elements, if they exist.

Return the total score obtained after all elements in nums are marked.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6