Score an array by taking the smallest and marking its neighbours

0
Remix

Start with every element of an array unmarked and a score of 0. Repeatedly pick the smallest unmarked value (the leftmost one on a tie), add it to the score, and mark it together with its left and right neighbours. When everything is marked, return the score. Use a heap or sorted indices so it runs in O(n log n).

AmazonTechnical phone screenLast asked Jan 2026
No answer yet. Write the first one; the best answer gets endorsed.