Skip to content

Practice Find Score of an Array After Marking All Elements

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2593
LeetCode Problem

Find Score of an Array After Marking All Elements

Problem Statement

Start with every nums entry unmarked and score 0. Choose the smallest unmarked value, breaking ties by smallest original index, add it to the score, and mark it and its immediate existing neighbors. Repeat until all are marked and return the score. Marking does not remove entries or change adjacency.

Source: Find Score of an Array After Marking All Elements on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,1,3,4,5,2]
Output
7

# Example 2

Input
nums = [2,3,5,1,3,2]
Output
5

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Find Score of an Array After Marking All Elements.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.