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.
OK, I need help on this one... I am getting the prefix sums in a vector s, and for each element i of the initial vector, I find the smallest element of s greater than s[i]. The difference between the two (mod M) gives me the max value for any subarray endind at i.
For efficiency, I keep only one copy of each value in s. I tried keeping these values in a set or in a hashmap.
How can I do more efficient than this? I keep getting time out errors... :(
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Subarray Sum
You are viewing a single comment's thread. Return to all comments →
OK, I need help on this one... I am getting the prefix sums in a vector s, and for each element i of the initial vector, I find the smallest element of s greater than s[i]. The difference between the two (mod M) gives me the max value for any subarray endind at i.
For efficiency, I keep only one copy of each value in s. I tried keeping these values in a set or in a hashmap.
How can I do more efficient than this? I keep getting time out errors... :(