Brick Break

Someone plz explain me how to do this problem…
Link -

My logic is to first check if there is 1 in the bricks, and if there is keep on breaking those bricks which are in between the bricks with their position numbered on it. But I don’t know how to implement this idea in the code.

Do one traversal, and find the largest n such that 1,2,…,n appears as a subsequence of the given sequence; (length of sequence - n) would be your answer; can be done in linear time

1 Like