Given an array of length N Every element of the array will be less than or equal to a given value M.At every level you will be given two integers L and R. your task is to output the answer of the following pseudocode at each level.
for i=L to R
for j=L to R if(a[i]==a[j]) ans=max(ans,j-i)
First line contains 3 integer N,M,Q.
N=Total number of elements in the array.
M is the maximum limit of Ai.
Q is the number of queries to be processed.
For each query print the required answer in new line.
5 3 3
1 2 3 2 1
a=2, a=2 ans=4-2=2
a=2, a=2 ans= 4-2=2
a=1 , a=1 ans=5-1=4
Can someone tell me an efficient approach??
can it be solved with Mo Algorithm?