• + 1 comment

    I did something pretty similar, just with a little bit more readable forEach:

    const arr = new Array(n).fill(0);
    let result = 0;
    
    queries.forEach(([a, b, k]) => {
        arr[a - 1] += k;
        if (b < arr.length) {
            arr[b] -= k;
        }
    });
    
    arr.reduce((a, b) => {
        const acc = a + b;
        result = Math.max(result, acc);
        return acc;
    }, 0);
    
    return result;
    
    • + 3 comments

      This produces wrong answer in some of the tests.

      • + 2 comments

        Hi,

        try this. Here is the video tutorial for my solution O(n+m) complexity.

        https://www.youtube.com/watch?v=hDhf04AJIRs&list=PLSIpQf0NbcCltzNFrOJkQ4J4AAjW3TSmA

        Would really appreciate your feedback like and comment etc. on my video.

        • + 1 comment

          It is a good video. I understood the algorithm clearly.

          • + 1 comment

            thanks @chandraprabha90.

            but it would be great if you can please provide your comments, like, dislike on my video how i did it..It motivates me to create better content for my audience.

            • + 2 comments

              Could you add subtitles? I tried watching it but couldn't quite understand your accent through the audio

              • + 0 comments

                Hi Grozny,

                I appologize for my bad sound quality but i am trying to improve it. but it will be very difficult to add subtitle for this video because its around half an hour which explains all the concepts in deep.

                Making this long video took lot of effort and time now adding a subtitle will be very tedious without any support.

                Will suggest you to try automatic transcribe feature from youtube to translate it.

                Anyway thanks for watching.

              • + 0 comments

                Hi Grozny,

                I have added subtitle for this tutorial and I hope it will you to understand logic with more clarity.

        • + 1 comment
          [deleted]
          • + 0 comments

            Nice approach you got there!

      • + 0 comments

        I had the same issue. my mistake was decrementing lower and upper. you don't decrement upper, the difference array needs to show it went down AFTER then last index, not within.