• + 3 comments

    Could you explain why this works?

    • + 3 comments

      Hi. I added a detailed answer to your question in my original post. Hopefully it helps, it was tough to explain.

      HackerRank solutions.

      • + 0 comments

        Awesome that definitely helped a lot! Thank you so much! :D

      • + 2 comments

        you are a great thinker rshaghoulian sir....Proud of you how to think like you... guide me

        • + 2 comments

          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.

          • + 0 comments

            I know this is kinda late, but holy, that is some genius work right here.

          • + 0 comments

            Lots of thanks for spending sooo much time and efforts to help us!

        • + 0 comments

          His thinking is his own skill/achievement, Why you are proud of him or his achievement???

      • [deleted]
        + 1 comment

        Thanks for the amazing explanation!

    • + 4 comments

      You can watch this video : https://youtu.be/JtJKn_c9lB4 Really short video of 7 mins and explained awesome

      • + 0 comments

        Thanks for it : )

      • + 0 comments

        Thanks for the vid, this helped me greatly!

      • + 0 comments

        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 "