← Questions
Score an array by taking the smallest and marking its neighbours
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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).
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
