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.
Hi. Thank you. Just keep coding and solving problems on HackerRank and you will steadily improve. Being active on the discussion forums is also a great learning experience. Best of luck.
Thanks !
If only all lthe explanations above said these words ,
"cumulative Slope algorithm works, when we add the value K only to the starting index(and assume it is being added until the end), but the Qs wants us to add only until till a index B, Therefore to stop the continous assumtion of adding K even after index B, we must put the index b+1 as -K. Thus from the working of our algorithm all the places form b+1 to end(inclusive) will be summed as (+K )+(-K), this way every new queries have to be started from their A index and ended at B by -K at B+ 1 , Now whe we cumulative add upto each index and replace it with the sum we get the previos ans array which we were getting from brute force
"
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Could you explain why this works?
Hi. I added a detailed answer to your question in my original post. Hopefully it helps, it was tough to explain.
HackerRank solutions.
Awesome that definitely helped a lot! Thank you so much! :D
you are a great thinker rshaghoulian sir....Proud of you how to think like you... guide me
Hi. Thank you. Just keep coding and solving problems on HackerRank and you will steadily improve. Being active on the discussion forums is also a great learning experience. Best of luck.
I know this is kinda late, but holy, that is some genius work right here.
Lots of thanks for spending sooo much time and efforts to help us!
His thinking is his own skill/achievement, Why you are proud of him or his achievement???
Thanks for the amazing explanation!
You can watch this video : https://youtu.be/JtJKn_c9lB4 Really short video of 7 mins and explained awesome
Thanks for it : )
Thanks for the vid, this helped me greatly!
Thanks ! If only all lthe explanations above said these words , "cumulative Slope algorithm works, when we add the value K only to the starting index(and assume it is being added until the end), but the Qs wants us to add only until till a index B, Therefore to stop the continous assumtion of adding K even after index B, we must put the index b+1 as -K. Thus from the working of our algorithm all the places form b+1 to end(inclusive) will be summed as (+K )+(-K), this way every new queries have to be started from their A index and ended at B by -K at B+ 1 , Now whe we cumulative add upto each index and replace it with the sum we get the previos ans array which we were getting from brute force "