What is the best algorithm or any short way to solve this problem Appy Loves One ,Please explain.?? I got only 30 pts,for brute force solution??
The editorial for this problem is here (link), which gives a few possibilities.
My own approach was:
- deal with the cases where there are no ones, one one or all ones
- find the runs of ones, if necessary with wraparound
- sort to find the longest such run and its position, plus the next longest, if any
- track the rotation described in the question as a mark moving through the array (representing the break)
- assess the mark position when a readout is required, to see if it’s in the largest run of ones.
- if so, calculate the longest intact run (otherwise the longest run is the answer)