How to find the minimum value in an array in a given range?

Revision en1, by I_love_Saundarya, 2019-04-13 10:47:45

We are give 2-arrays, one array is called the original array and other is the corresponding array.

Example : -

a:- [5,6,5,7,5,5,5,8,9]

a':-[1,2,3,1,2,3,1,2,1]

We are given 3-values:- 'l','r' and 'x'

Let l=3 and r=7, also x=5,

so we check the occurrences of '5' in the range [3,7] , so a[3],a[5],a[6],a[7] are the indices which contain '5' .

Now,we check the corresponding array's values,i.e, a'[3],a'[5],a'[6],a'[7] which are:- '3','2','3' and '1'. The minimum of these is '1' and hence the output will be :- "1" .

I know the brute-force approach for multiple queries like this, but I'm interested in an efficient approach !

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English I_love_Saundarya 2019-04-13 10:47:45 707 Initial revision (published)