USACO Bronze Test - Lonely Photo

Hi, I revently took the USACO Bronze December contest, and I was struggling on how to find a better complexity for the problem Lonely Photo. I was able to get the brute force algorithm which worked when N <= 50 but I wasn’t able to find a better algorithm. Can someone please give me a hint on this problem or where to start?


What is the current time complexity of your solution?

A hint would be to start counting the number of consecutive holsteins and guernseys around one point.