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's a cumulative sum. Add each element in the array sequentially and store the maximum value of the sum as you iterate through.
Starting at index 0, your max sum is 3. Once you hit index 4, max sum is now 10. This is the max that it ever reaches, as it becomes 8 at index 6, 1 at index 9, and 0 at index 10.
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 →
It's a cumulative sum. Add each element in the array sequentially and store the maximum value of the sum as you iterate through.
Starting at index 0, your max sum is 3. Once you hit index 4, max sum is now 10. This is the max that it ever reaches, as it becomes 8 at index 6, 1 at index 9, and 0 at index 10.