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: