# Codility Peaks

#### Posted on January 2, 2014

##### Last updated on January 3, 2014

Solution to Codility Peaks problem.

First, we need to find all the peaks. Simply iterate through all elements and aggregate all the peaks into $$P$$.

Then, we can iterate through the various possible group sizes $$g \in [1,N]$$. We need the least $$g$$ such that $$g | N$$ (then $$\frac{N}{g}$$ is maximized) and so that every group of size $$g$$ has at least one peak. This can be done by simply iterating through all the peaks $$p \in P$$ and checking if every has peak. The 100/100 Java code:

Markdown SHA1: 940023d5b562b730ffac1a8ed4b497ddb04e5663