Given an array of n elements. ‘n’ operations needs to be performed on the array. For each operation start_index, end_index,trim_value is given. One has 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. After performing ‘n’ operations find the maximum value of the array.
A simple offline solution would be to keep 2 sets on all indices, one for insert and one delete. For all updates, put value trim_value to the insertion set of start_index and deletion set of end_index. Now, iterate over the array keeping another multi-set storing all the updates that apply to current index, the value of this element is essentially min value in multi set and that value it self. Insertion and deletion are also done in O(\log N) as there are n updates. Time complexity is O(N \log N).