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.
I had fun solving this with C in 45 lines by calculating two constant sized tables before seeing any Q's and after that I'm just doing array lookups using the sum of all Q's so far.
So my space is O(1) and time O(Q + N), and I did get rid of the 4001'ish Q multiplier in time as well which few people mentioned; I had that version at first too, but it failed the last two tests :)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Absolute Element Sums
You are viewing a single comment's thread. Return to all comments →
I had fun solving this with C in 45 lines by calculating two constant sized tables before seeing any Q's and after that I'm just doing array lookups using the sum of all Q's so far. So my space is O(1) and time O(Q + N), and I did get rid of the 4001'ish Q multiplier in time as well which few people mentioned; I had that version at first too, but it failed the last two tests :)