you have given array of integers
for example 5,3,4,3,9,4,4,6,8,6,5,7
you have to find largest interval (i,j) such that all number between i and j are greater than equal to number at i but less than equal to number at j. numbers need not to be in sorted order. Also number at i should be less than number at j.
in above example there are two such intervals 3,4,3,9 and 4,4,6,8
In 3,4,3,9 - middle two numbers (4,3) are greater than equal to starting number(3) but less than equal to ending number(9) . Also starting number (3) is less than ending number(9).
In 4,4,6,8 - middle two numbers (4,6) are greater than equal to starting number(4) but less than equal to ending number(8). Also starting number(4) is less than ending number(8).
One way to solve this problem is check all intervals of size n, then size n-1 , so on till we get such interval. But I want efficient algo either by Divide or Conquer /DP/or some other approach