Back to Browse

Codility Flags solution

2.7K views
Jul 23, 2021
16:49

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.

Download

1 formats

Video Formats

360pmp423.6 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Codility Flags solution | NatokHD