Most optimized Solution

Revision en1, by go_rob, 2017-04-10 08:44:46

Given an array of n elements. ‘k’ operations need to be performed on the array.

For each operation start_index, end_index,trim_value is given. One has to trim the value starting from the start_index to end_index inclusive.

If the value at that index is more than or equal to trim value then make it equal to trim_value else leave it as it is. for each A[i] for i between start and end , A[i] = min(A[i],h) .

After performing, ‘k’ such operations find the maximum value of the array.

I have a solution of O(n + k*log(n)). I think it can be optimized to O( n*log(n) ) at least, if not better.

Note: Please try not to use Segment tree or BIT.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English go_rob 2017-04-10 08:58:54 8
en3 English go_rob 2017-04-10 08:56:16 84 (published)
en2 English go_rob 2017-04-10 08:52:27 320
en1 English go_rob 2017-04-10 08:44:46 711 Initial revision (saved to drafts)