• + 0 comments

    The magic thing about this is that it's all about prefix-sum... Seriously, when i understood the logic i tought how funny and simple is that solution... That's why algorithms is so amazing to me.

    PS: To avoid the if in the q + 1 <= N just add 2 to the size of the array instead of 1.