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
.