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.
If you already have the sum of a subarray (like the starred elements in [***___]), then you can get sum of the subarray with indices shifted right by 1 (for the previous example, [_***__]) by adding one element and subtracting another.
Prince_sai's solution gets O(n) runtime in a different way: a cumulative sum array.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division
You are viewing a single comment's thread. Return to all comments →
If you already have the sum of a subarray (like the starred elements in
[***___]
), then you can get sum of the subarray with indices shifted right by 1 (for the previous example,[_***__]
) by adding one element and subtracting another.Prince_sai's solution gets O(n) runtime in a different way: a cumulative sum array.