Flags is the second exercise in lesson 10, prime and composite numbers, of Codility. The aim is to count the number of flags that can be placed on the peaks of a mountain range. The flags must be spaced apart by the same distance as the total number of flags placed on the peaks.
This is a respectable task and it is quite challenging. My solution first finds the peaks in the mountain range. Next, I find the maximum number of flags that would be possible to place on the peaks. Finally, I loop through down from the maximum number of flags and attempt to place the flags on the peaks from both ends.
The solution scores 100% on Codility.
Edit: It didn't really deserve 100%... take a look at the pinned comment.