• + 0 comments

    Phew, so finally solved this after weeks. It basically comes down to idea of min_queue problem. i.e, you can look up minimum of 'M' consecutive terms as you move from left to right in an array in O(1).

    Two stacks!