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.
This is called 'sliding window' approach.
We need a contiguous segment of specified length, and that segment should match some requirements.
We store the start of the segment and everytime time the length of the segment is equal to the required one (to calculate the length we subtract start index from the current index), we increment the start index to find another segment already starting with the next element and with the specified length.
And, as we sum elements on the go, we need to subtract the start element value from the total sum, so to have a currect sum for the next segment.
Let me know if it is still unclear.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division 1
You are viewing a single comment's thread. Return to all comments →
Hi,
Of course!
This is called 'sliding window' approach. We need a contiguous segment of specified length, and that segment should match some requirements. We store the start of the segment and everytime time the length of the segment is equal to the required one (to calculate the length we subtract start index from the current index), we increment the start index to find another segment already starting with the next element and with the specified length.
And, as we sum elements on the go, we need to subtract the start element value from the total sum, so to have a currect sum for the next segment.
Let me know if it is still unclear.