I have a problem with this:
We have an integer array (size n) [x_1,x_2,...,x_n]
We have to find the longest common part [x_i,x_i+1,...,x_j] that minimum of (x_i,x_i+1,...,x_j) >= j-i+1 f.e [2,2,1,4,3,3,1] -> 3(the longest correct part is 4,3,3 )
I can't figure out how to reduce time below O(n^2) (Checking every single segment)
My second idea was: Every value x_k is equal to the "length range" that this part may have, if there is lower number then we change "length range" (in a meanwhile counting how long is this segment), but I don't have a clue what to do if we get greater numbers
(I would be really thankful for any help - there is probably another simpler solution, but I don't see it)