The Find Score of an Array After Marking All Elements interview question is a simulation problem. You start with a score of 0. In each step, you find the smallest unmarked element in the array (picking the smallest index if there's a tie). You add its value to your score and mark it, along with its immediate left and right neighbors. You repeat this until all elements are marked.
Companies like Visa and Bloomberg ask the Find Score coding problem to test your ability to use Heaps or Sorting to efficiently find minimum values in a dynamic state. It evaluations whether you can maintain a "marked" state correctly and avoid redundant searches. It's a great test of Heap (Priority Queue) interview patterns.
This problem is solved using Sorting and a Visited Array.
(value, index) for every element in the array.marked array. For each pair (val, idx) in sorted order:
marked[idx] is false:
score += val.marked[idx] = true.marked[idx - 1] = true (if valid).marked[idx + 1] = true (if valid).Array: [2, 1, 3, 4, 5, 2]
(1, 1), (2, 0), (2, 5), (3, 2), (4, 3), (5, 4).score = 1. Mark indices {0, 1, 2}.score = 1 + 2 = 3. Mark indices {4, 5}.score = 3 + 4 = 7. Mark index {3}.
All marked. Result: 7.idx-1 or idx+1.When a problem asks you to repeatedly find the "best" element, your first instinct should be a Heap or Sorting. If the "best" criteria is fixed (like value and index), sorting once is usually easier to implement than a dynamic heap.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Mark Elements on Array by Performing Queries | Medium | Solve | |
| Meeting Rooms III | Hard | Solve | |
| Max Sum of a Pair With Equal Sum of Digits | Medium | Solve | |
| Make Array Zero by Subtracting Equal Amounts | Easy | Solve | |
| Relocate Marbles | Medium | Solve |