We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It is not necessery to store full array. It is sufficient to store only begins and ends of all intervals (A and B).
For example, if you have 10^7 elements and one operation, you need only 2 points, not 10^7.
But in some languages (for example pure C) you will need to implement someone ordered container with fast insert operation, for example ordered List.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
My solution, O(M*log(M)):
It is not necessery to store full array. It is sufficient to store only begins and ends of all intervals (A and B). For example, if you have 10^7 elements and one operation, you need only 2 points, not 10^7. But in some languages (for example pure C) you will need to implement someone ordered container with fast insert operation, for example ordered List.