The task description is here: https://codility.com/demo/take-sample-test/peaks It's also here: Codility Peaks Complexity
First, I tried solving this myself but was only able to come up with what I believed to be a brute force solution. However, it scored 100/100: https://codility.com/demo/results/demoRNWC3P-X4U
Which obviously is completely unsatisfying for me. ;) The outer loop is called for each factor of N
(or for each peak, whichever is smaller) and the inner one is called for each peak (just checking if there's a peak in every block). Maybe that's O(N^2)
, maybe a bit better (since it passes the tests in time limits) but I'm almost sure it's not O(N*log(log(N)))
.
Then I tried searching for an O(N*log(log(N)))
solution but everyone else seems to have a pretty similar solution to mine.
So does anyone have an idea for an O(N*log(log(N)))
(or a better one) solution?
Also, if anyone could tell me what complexity my solution has I'd be grateful.