← Questions

Score an array by taking the smallest and marking its neighbours

0
AmazonCodingLast asked Jan 2026

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).

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding