Master_coder's blog

By Master_coder, history, 6 months ago, In English,

Given N keys and values , and q queries for each query you have given key you have to find key smaller than given key with maximun value . for example:- keys — 2 3 1 6 4 values — 5 1 6 2 8 given key 5 must produce output 8 i.e (4,8)

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 months ago, # |
  Vote: I like it +7 Vote: I do not like it

Sort the keys. Make another array that Max. Max[I] will store the maximum value till index I. You can search the index where the key is just smaller than the input key with lower_bound. Let the index is Ind then the answer is nothing but Max[Ind].